|
5鱼币
本帖最后由 huangdongdong 于 2021-3-20 15:25 编辑
- f = open('E:\\something.txt')
- boy = []
- girl = []
- count = 1
- for each_line in f:
- if each_line[:6] != '======':
- (role,line_soplen) = each_line.split(':',1)
- if role == '小甲鱼':
- boy.append(line_spoken)
- if role == '小客服':
- girl.append(line_spoken)
- else:
- file_name_boy = 'boy_' + str(count) + '.txt'
- file_name_girl = 'girl_' + str(count) + '.txt'
- f1 = open(file_name_boy,'w')
- f2 = open(file_name_girl,'w')
- f1.writelines(boy)
- f2.writelines(girl)
-
- f1.close()
- f2.close()
-
- boy = []
- girl = []
- count += 1
- f.close(
复制代码- Traceback (most recent call last):
- File "C:\Users\ASUS\Desktop\1.py", line 5, in <module>
- for each_line in f:
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 4: illegal multibyte sequence
复制代码
编码问题,你试试修改代码
- f = open('E:\\something.txt',encoding='utf-8')
复制代码
|
|