|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大家好, 老是遇到这个错误,问题究竟在哪里啊
这个是代码:
f = open ("f:\\record.txt")
boy=[]
girl=[]
count =1
for each_line in f:
if each_line[:6] != '=======':
(role,line_spoken) = each_line.split(':',1)
print(role,line_spoken)
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_filr.close()
boy=[]
girl=[]
count+=1
f.close()
感觉和视频的一样,结果总是报错
Traceback (most recent call last):
File "F:/python.save/file.py", line 9, in <module>
(role,line_spoken) = each_line.split(':',1)
ValueError: not enough values to unpack (expected 2, got 1)
程序要求将读取的每行以 : 为界分为两部分,如果找不到 : 就会报错。可能是record.txt文件中误写成中文冒号了
|
|