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

Python教程之src转为html

程序员文章站 2022-04-08 23:17:07
...

实战需求

Python教程之src转为html

实战代码

fname = "1. What is Vapor"                                                  
fname_ext = "srt" 
rname = fname+"_br.html"  
rstr = ""                 
flines = open(fname+"."+fname_ext).readlines()  

for item in flines: 
	rstr = rstr + item.replace("\n","<br><br>\n")  

with open(rname,'w') as r:
	r.write(rstr)
	

fname = "en.srt"                                                  
rname = "zh.srt"  
rstr = ""                 
flines = open(fname).readlines()  

for item in flines: 
	if item == "\n":
		continue
	else:
		rstr = rstr + item

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