|  | 
 
| 
请教各位python鱼油:
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 在做文件写入的作业时,我按书上的代码敲入:
 def save_file(boy, girl, count):
 '''establish 6 separate files'''
 file_name_boy = 'boy'+ str(count)+'.txt'
 file_name_girl = 'boy'+ 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()
 def split_file(file_name):
 count = 1
 boy = []
 girl = []
 f = open(file_name)
 for each_line in f:
 if each_line != "== == ==":
 (role, line_spoken) = each_line.split(':', 1)
 if role == '小甲鱼':
 boy.append(line_spoken)
 if role == '小客服':
 girl.append(line_spoken)
 else:
 save_file(boy, girl, count)
 boy = []
 girl = []
 count += 1
 save_file(boy, girl, count)
 f.close()
 split_file('D:/record.txt')
 检查几遍觉得没问题,但是在运行时,老是出现以下错误提示:
 raceback (most recent call last):
 File "D:\Practice\fileoperation.py", line 30, in <module>
 split_file('D:/record.txt')
 File "D:\Practice\fileoperation.py", line 18, in split_file
 (role, line_spoken) = each_line.split(':', 1)
 ValueError: not enough values to unpack (expected 2, got 1)
 这是什么毛病呢?难道因为我最近下载了一些模块有关吗?
 | 
 |