如何用python将srt文件转化成数组形式

11 篇文章 1 订阅

原srt文件

0
00:00:00,150 --> 00:00:11,430
Fighting this pandemic needs political commitment and commitment at the highest level possible and the President's commitment.

1
00:00:11,431 --> 00:00:16,020
you have what it is in it and the would it have seen it.

2
00:00:16,021 --> 00:00:19,320
and that kind of leadership is very,

3
00:00:19,321 --> 00:00:20,160
very important.

4
00:00:20,161 --> 00:00:21,570
The whole of government approach.

转化之后的数组(将时间和内容分离)

['00:00', '00:11', '00:16', '00:19', '00:20']

["Fighting this pandemic needs political commitment and commitment at the highest level possible and the President's commitment.", 'you have what it is in it and the would it have seen it.', 'and that kind of leadership is very,', 'very important.', 'The whole of government approach.']

下面贴出转化的代码,即将cte_test.srt转化成数组
之后可以考虑输送到mysql数据库上进行复用

count1 = 1
count2 = 2
ktime = []
klrc = []

with open('cte_test.srt', 'r') as f:
    for index, value in enumerate(f.readlines()):
        if index==count1:
            value= value.strip()[3:8]
            ktime.append(value)
            count1=count1+4
        elif index==count2:
            value= value.strip()
            klrc.append(value)
            count2=count2+4

print(ktime)
print(klrc)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值