求助!!!!
count=1boy=[]
girl=[]
f=open('record.txt')
for each_line in f:
if each_line[:6] !='=======':
(role,line_spoken)=each_line.split(':',1)
if role=='小甲鱼:':
boy.append(line_spoken)
if role=='小客服':
girl.append(line_spoken)
else:
file_name_boy: str='boy_'+str(count)+'.txt'
file_name_girl='girl_'+str(count)+'.txt'
boy_file=open(file_name_boy,'w')
girl_file=open(file_name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy=[]
girl=[]
count+=1
file_name_boy='boy'+str(count)+'.txt'
file_name_girl='girl'+str(count)+'.txt'
boy_file=open(file_name_boy,'w')
girl_file=open(file_name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
f.close
*****************************************
C:\Users\hq\PycharmProjects\pythonProject1\venv\Scripts\python.exe C:/Users/hq/Desktop/新建文件夹/2.py
Traceback (most recent call last):
File "C:\Users\hq\Desktop\新建文件夹\2.py", line 5, in <module>
for each_line in f:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 4: illegal multibyte sequence
进程已结束,退出代码为 1
***************************************
求大神指点!照书编写的,为什么报这样的错,谢谢!!! python文件和record文件放在桌面同一文件下的 编码问题,一般用utf-8的比较多
f = open('record.txt',"r",encoding='UTF-8')
页:
[1]