我对Python和编程都是新手,我尝试从文本文件(包含字幕)创建srt文件
这是我的代码:with open("in3.txt") as f:
lines = f.readlines()
# lines = [l for l in lines]
with open("out.txt", "w") as f1:
for x in range(0, 7):
y = x*10
f1.write("\n00:01:"+str(y)+"\n")
f1.writelines(lines)
这就是我得到的:
00:01:0
This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line
00:01:10
This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line
00:01:20
This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line
...
然而,期望的结果是:
00:01:0
This is 1st line
00:01:10
This is 2nd line
00:01:20
This is 3rd line
00:01:30
This is 4th line
in3.txt包含:This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line
任何帮助都将不胜感激:)
谢谢
python将一个文本文件复制到另一个文件中_使用Python逐行从一个文本文件复制到另一个文本文件...