| if __name__ == '__main__': | | readfile = 'E:/news/Python/lr.txt' | | writefile = 'E:/news/Python/srt.txt' | | count = 0 | | with open(readfile, 'r', encoding='gbk') as f: | | lines = f.readlines() | | for i in range(len(lines)): | | count += 1 | | if i / 2: | | time = '00:' + lines[i-1].split(']')[0][1:] + '9' + ' --> ' + '00:' + lines[i].split(']')[0][1:] + '0' | | time = time.replace('.', ',') | | srt = lines[i-1].split(']')[1].strip('\n') | | with open(writefile, 'a', encoding='gbk') as ff: | | ff.write(str(count-1) + '\n') | | ff.write(time + '\n') | | ff.write(srt) | | ff.write('\n'*2)COPY |
|