如何让这个程序将更改写入输入文件的原始副本或新副本?

时间:2016-11-24 13:17:05

标签: python

此程序适用于我,除了对输入.srt(字幕)文件所做的更改显示但未保存回输入文件或新文件。谁能告诉我缺少什么?谢谢。斯图尔特。

代码如下:

#! /usr/bin/python
import sys;

# Patching SRT files to make them readable on Samsung TVs
# It basically inserts blank subtitles when silence should occur.

seqNo=1

try:
    subs = open(sys.argv[1])
except:
    print "Please provide subtile file to process"
    sys.exit(1)

while True:
    srtSeqNo=subs.readline();
    try:
        begin,arrow,end=subs.readline().rstrip('\n\r').split(" ")
    except:
        break
    srtText = subs.readline();
    again = subs.readline();
    while len(again.strip('\n\r')) > 0:
        srtText = srtText + again
        again = subs.readline()
    print "%d\n%s --> %s\n%s" % (seqNo, begin, end, srtText)

    seqNo = seqNo + 1
    print "%d\n%s --> %s\n%s\n" % (seqNo, end, end, "   ")
    seqNo = seqNo + 1

0 个答案:

没有答案