大家好,我在输出带有时间戳的文件时遇到了一点问题,这是我的代码
input_file = open('DVBSNOOP/epg_slo_sort.txt', "r") # read
output_file = open('SORT/epg_slo_xml.txt', "w") # write
for line in input_file:
line = re.sub(r"\d{8}:|\d{7}:|\d{6}:|\d{5}:|\d{4}:","", line) # remove nubers from start line example --> 10072633: etc...
line = line.replace("[= --> refers to PMT program_number]","").replace("Service_ID:","Program") # remove = --> refers to PMT program_number] and replace Service_ID to Program
line = line.replace("0xdce","").replace("Start_time:","Start") # remove 0xdce and change Start_time to start
line = line.replace("0x0","") # remove 0xdce
line = line.replace("event_name:","Title") # change to Title from event_name
line = line.replace("Program: 14 (00e)","") # remove program 14 does not exist
line = line.replace("-- Charset: ISO/IEC 8859 special table","") # remove -- Charset: ISO/IEC 8859 special table
line = line.replace("-- Charset: ISO/IEC special table","")# remove -- Charset: ISO/IEC special table
line = line.replace("[=","").replace("]","") # remove [=]
line = line.replace("Duration:","Duration").replace("0x00","").replace("0x000","").replace("0x","")
line = line.replace('"..',"").replace('"',"").replace(" . . .","").replace("-","") # remove ".."
line = re.sub(r"Start: \d{2}|\d{4}|\d{3}|\d{7}\d{9}\d{6}","",line) # remove numbers after
line = re.sub(r"Duration: \d{2}|\d{6}|\d{7}|d{5}\d{8}\d{4}|\d{3}|\d{9}","Duration",line) # remove numbers affter data
line = re.sub(r"^//","",line) # remove / /
line = re.sub(r"\([^)]*\)","",line) # remove brackets
line = re.sub(r"Program 14","",line) # remove program 14
output_file.write(line) # write to file
我希望我的输出像epg_slo_sort(M;D;Y:Time).txt
.