#想学英语,下了英语字幕,发现有很多时间戳,打印下来会很占空间,于是用python将时间戳去掉。

def model1():
f1=open('coherence.txt','r')#将下载的字幕复制(或者更名)为coherence.txt(只要是txt文件即可)并放在python根目录下
f2=open('test2.txt','w')#打开(没有则新建)test2文件
a=[':',',','>','1','2','3','4','5','6','7','8','9','0','-']
for line in f1:
for s in line:
if str(s) in a:
line=line.replace(s,'')#改为空号
f2.write(line)
f1.close()
f2.close()
def model2():
f2=open('test2.txt','r')
f3=open('test3.txt','w')
for line in f2:
if line.split():
f3.write(line)
f3.close()

model1()
model2()


以上分为两部分完成字幕更改,第一部分将':',',','>','1','2','3','4','5','6','7','8','9','0','-'都改为空号,第二部分将空号及空行去掉
效果如下:
原本字幕:
python对字幕的改动
修改后的字幕:
python对字幕的改动

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-11-11
  • 2022-01-20
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2021-12-25
  • 2021-06-04
  • 2022-12-23
  • 2021-05-30
  • 2022-03-06
  • 2022-12-23
相关资源
相似解决方案