零基础入门学习python的第31课后题,求大佬告诉我为什么报这个错误
import picklecount=1
dialog1=['oj']
dialog2=['bk']
boy_file_name='小甲鱼_1.txt'
girl_file_name='小客服_1.txt'
tell=open('record.txt')
for each_line in tell:
if each_line[:6]!= '======':
if each_line.split(':')=='小甲鱼':
dialog1.append(each_line.split(':'))
if each_line.split(':')=='小客服':
dialog2.append(each_line.split(':'))
else:
f=open(boy_file_name,'wb')
m=open(girl_file_name,'wb')
pickle.dump(dialog1,boy_file_name)
pickle.dump(dialog2,girl_file_name)
f.close()
m.close()
count+=1
boy_file_name='boy_'+str(count)+'.txt'
girl_file_name='girl_'+str(count)+'.txt'
dialog1=[]
dialog2=[]
tell.close()
Traceback (most recent call last):
File "C:\Users\86187\Desktop\dialog.py", line 20, in <module>
pickle.dump(dialog1,boy_file_name)
TypeError: file must have a 'write' attribute
页:
[1]