马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Rider.vl0 于 2019-7-10 22:20 编辑 import codecs
f = open("D:\\File\\测试文档.txt",encoding='iso-8859-15')
boy =[]
girl = []
cunoe = 1
for each_sdk in f:
if each_sdk[:6] != "=======":
(reo,line_spoken) = each_sdk.split(":",1)
if reo == "小甲鱼":
boy.append(line_spoken)
if reo =="小客服":
girl.append(line_spoken)
else:
name_girl = "girl_"+ str(cunoe) + '.txt'
name_boy = 'boy_'+ str(cunoe) + '.txt'
boy_file = open(name_boy,"w")
girl_file = open(name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
boy= []
girl = []
cunoe += 1
name_girl = "girl_"+ str(cunoe) + '.txt'
name_boy = 'boy_'+ str(cunoe) + '.txt'
boy_file = open(name_boy,"w")
girl_file = open(name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
f.close()
我自己与视频教学中的代码检查过了没有问题但是报错,求救啊Traceback (most recent call last):
File "D:\File\新建文本文档.py", line 9, in <module>
(reo,line_spoken) = each_sdk.split(":",1)
ValueError: not enough values to unpack (expected 2, got 1)
|