purpose:
The different characters say are preserved
In ========== segment
Code:
1 f=open('record.txt','r',encoding='UTF-8')
2
3 zyf=[]
4 smy=[]
5 count=1
6 def writefile(filename,liebiao,count):
7 file_name=open(filename+str(count)+'.txt','w',encoding='UTF-8')
8 file_name.writelines(zyf)
9 file_name.close()
10
11 for each_line in f:
12 if each_line[:6]=="======":
13 #写入
14 writefile('zyf',zyf,count)
15 writefile('smy',smy,count)
16 count=count+1
17 zyf=[]
18 smy=[]
19 else:
20 line_split=each_line.split(sep=":",maxsplit=1)
21 if line_split[0]=='zyf':
22 zyf.append(line_split[1])
23 if line_split[0]=='smy':
24 smy.append(line_split[1])
25
26 writefile('zyf',zyf,count)
27 writefile('smy',smy,count)
28 f.close()
29
Process issues:
Coding problem, simply Open ( ' record.txt ', ' R & lt ', encoding = ' UTF-. 8 ' ) specified encoding
int->str:str()
Results: