欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python教程之如何将srt转为文本

程序员文章站 2022-04-08 23:16:49
...

实战需求

python教程之如何将srt转为文本

实战代码

def split2step(alist,step):
	rs = []
	for i in range(0,len(alist),step):
		rs.append(alist[i:i+step])
	
	return rs
	
fname = "1. What is Vapor.srt"                                                
rname = "1. What is Vapor_en.html"               
flines = open(fname).readlines()  
f4 = split2step(flines,4)	
rs = ""
for item in f4:
	rs = rs+item[2].replace("\n","")

with open(rname,'w') as r:
	r.write(rs)
相关标签: Python源码大全