关于value错误的问题
Traceback (most recent call last):File "E:/Python-3.8.5/程序/课堂练习/对话.py", line 10, in <module>
(role, line_spoken) = each_line.split(':', 1)
ValueError: not enough values to unpack (expected 2, got 1)
代码是这样:
g = open('E:\\conversation.txt')
boy = []
girl = []
for each_line in g:
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 = '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.colse()
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.colse()
f.colse()
就是照抄课上的,,但不知道出了啥问题 本帖最后由 kylin121380 于 2020-9-8 19:53 编辑
文件中夹杂了空行?或者中英文的:出错了? kylin121380 发表于 2020-9-8 19:50
文件中夹杂了空行?或者中英文的:出错了?
这个好像不是,,,中英文报错应该不一样吧, kylin121380 发表于 2020-9-8 19:50
文件中夹杂了空行?或者中英文的:出错了?
好像是,,,我代码中弄的是英文的:,,文档中的是中文的:谢谢啊
大执法官 发表于 2020-9-8 20:18
好像是,,,我代码中弄的是英文的:,,文档中的是中文的:谢谢啊
那给个最佳答案吧{:10_254:}
页:
[1]