|
发表于 2018-10-26 22:37:44
From FishC Mobile
|
显示全部楼层
|阅读模式
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码:
import pickle
def file_write(file_name):
f = open(file_name,'w')
while True:
write_sth = input('请输入内容[输入\':w\'退出程序]:')
if write_sth != ':w':
f.write('%s\n' % write_sth)
f.close()
f = open(file_name,'ab')
pickle.dump(write_sth,f)
else:
print('Thx for use NotePad Program.')
break
f.close()
print('请输入文件名:',end = ' ')
file_name =input()
file_write(file_name)
每当我运行第一次输入没报错,第二次就报错
报错内容是:NotePad.py", line 7, in file_write
f.write('%s\n' % write_sth)
TypeError: a bytes-like object is required, not 'str'
请问怎么解决呢…… |
|