[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. if __name__ == '__main__':
  2.     readfile = 'E:/news/Python/lr.txt'
  3.     writefile = 'E:/news/Python/srt.txt'
  4.     count = 0
  5.     with open(readfile, 'r', encoding='gbk') as f:
  6.         lines = f.readlines()
  7.         for i in range(len(lines)):
  8.             count += 1
  9.             if i / 2:
  10.                 time = '00:' + lines[i-1].split(']')[0][1:] + '9' + ' --> ' + '00:' + lines[i].split(']')[0][1:] + '0'
  11.                 time = time.replace('.', ',')
  12.                 srt = lines[i-1].split(']')[1].strip('\n')
  13.                 with open(writefile, 'a', encoding='gbk') as ff:
  14.                     ff.write(str(count-1) + '\n')
  15.                     ff.write(time + '\n')
  16.                     ff.write(srt)
  17.                     ff.write('\n'*2)
复制代码

TOP

返回列表