|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
返回的错误如下:
Traceback (most recent call last):
File "/Users/effy/Desktop/python/hhh.py", line 36, in <module>
split_file()
File "/Users/effy/Desktop/python/hhh.py", line 21, in split_file
(role, role_spoken) = each_line.split(':',1)
ValueError: not enough values to unpack (expected 2, got 1)
- def save_file(boy,girl,count):
- file_name_boy = 'boy_' + str(count) +'.py'
- file_name_girl = 'girl_' + str(count) +'.py'
- file_boy = open(file_name_boy,'w')
- file_girl = open(file_name_girl,'w')
- file_boy.writelines(boy)
- file_girl.writelines(girl)
- file_boy.close()
- file_girl.close()
-
- def split_file():
- f = open('/Users/effy/Desktop/open.py')
- boy = []
- girl = []
- count = 1
- for each_line in f:
- if each_line[:6] != '======':
- (role, role_spoken) = each_line.split(':',1)
- if role == '小甲鱼':
- boy.append(role_spoken)
- elif role == '小客服':
- girl.append(role_spoken)
- else:
- save_file(boy,girl,count)
- boy = []
- girl = []
- count += 1
- save_file(boy,girl,count)
- f.close()
- split_file()
-
复制代码 |
|