#处理小时,和分钟字母串 def myHandle(she): kaishi_shi = she if len(str(kaishi_shi)) < 2: kaishi_shi_str = "0%s" % str(kaishi_shi) else: kaishi_shi_str = str(kaishi_shi) print(kaishi_shi_str) return kaishi_shi_str #处理开始时间字符串 #开始时间串为,如,00:59:59,300 def myHandelKaiShi(kaishishijianchuan): fir_list_one_list = kaishishijianchuan.split(":") print(fir_list_one_list) kaishi_shi_fen = int(fir_list_one_list[0]) * 60 + int(fir_list_one_list[1]) - 39 kaishi_shi = int(kaishi_shi_fen / 60) print(kaishi_shi) kaishi_fen = int(kaishi_shi_fen % 60) print(kaishi_fen) print("再次拼接") kaishi_shi_str = myHandle(kaishi_shi) # 处理时 kaishi_fen_str = myHandle(kaishi_fen) # 处理分 new_kaishi_shijian_str = "%s:%s:%s" % (kaishi_shi_str, kaishi_fen_str, fir_list_one_list[2]) print(new_kaishi_shijian_str) return new_kaishi_shijian_str #处理结束时间字符串 #结束时间串为,如, 00:39:57,360 def myHandelJieShu(jieshushijianchuan): kaishishijianchuan = jieshushijianchuan fir_list_one_list = kaishishijianchuan.split(":") print(fir_list_one_list) kaishi_shi_fen = int(fir_list_one_list[0]) * 60 + int(fir_list_one_list[1]) - 39 kaishi_shi = int(kaishi_shi_fen / 60) print(kaishi_shi) kaishi_fen = int(kaishi_shi_fen % 60) print(kaishi_fen) print("再次拼接") kaishi_shi_str = myHandle(kaishi_shi) # 处理时 kaishi_fen_str = myHandle(kaishi_fen) # 处理分 new_kaishi_shijian_str = " %s:%s:%s" % (kaishi_shi_str, kaishi_fen_str, fir_list_one_list[2]) print(new_kaishi_shijian_str) new_jieshu_shijian_str = new_kaishi_shijian_str return new_jieshu_shijian_str with open(r'zhong-3.srt' , 'r', encoding='utf-8') as f: read_list = f.readlines() print(read_list) for one in read_list: xietu_content ='' one_qudiao = one.strip("\n") if "-->" in one: fir_list = one.split("-->") print(fir_list) kaishishijianchuan = fir_list[0] new_kaishishijianchuan = myHandelKaiShi(kaishishijianchuan) jieshushijianchuan = fir_list[1] new_jieshushijianchuan = myHandelJieShu(jieshushijianchuan) new_content = "%s-->%s" %(new_kaishishijianchuan,new_jieshushijianchuan) print("new_content:") print(new_content) xietu_content = new_content else: if one_qudiao.isdigit(): print("%s去掉换行后仅是数字") xietu_content = "\n"+str(int(one)-399)+"\n" else: xietu_content = one with open(r'xin.srt', 'a+', encoding='utf-8') as f: read_list = f.write(xietu_content)
标签:python,list,改变,字幕,str,print,shi,fen,kaishi From: https://www.cnblogs.com/jingzaixin/p/18111231