|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
跟原答案对比了几遍,没有找出问题……求大神指点!
原题目:
编写一个程序,这次要求使用pickle将文件( 见附件 )里的对话按照以下要求腌制成不同文件(没错,是第29讲的内容小改,考考你自己能写出来吗?):
小甲鱼的对话单独保存为boy_*.txt的文件(去掉“小甲鱼:”)
小客服的对话单独保存为girl_*.txt的文件(去掉“小客服:”)
文件中总共有三段对话,分别保存为boy_1.txt, girl_1.txt,boy_2.txt, girl_2.txt, boy_3.txt, gril_3.txt共6个文件(提示:文件中不同的对话间已经使用“==========”分割)
代码内容:
- import os
- import pickle
- def save_file(boy,girl,count):
- boy_file = 'boy_' + str(count) +'.txt'
- girl_file = 'girl_' +str(count) +'.txt'
- b = open(boy_file,'wb')
- g = open(girl_file,'wb')
- pickle.dump(boy,b)
- pickle.dump(girl,g)
- b.close()
- g.close()
- def split_file(file_name):
- boy = []
- girl = []
- count = 1
- os.chdir(r'E:\06 goodstudydayup\python')
- f = open(file_name)
-
- for each_line in f:
- if each_line[:6] != "======":
- (name,words) = each_line.split(':',1)
- if name == '小甲鱼':
- boy.append(words)
- if name == '小客服':
- girl.append(words)
- else:
- save_file(boy,girl,count)
-
- boy = []
- girl = []
- count += 1
- save_file(boy,girl,count)
- f.close()
- save_file('record.txt')
-
复制代码
错误类型:
TypeError: save_file() missing 2 required positional arguments: 'girl' and 'count'
接口: - def save_file(boy,girl,count):
复制代码调用 秀儿是你吗?
|
|