pickle 需要“写”;属性?
我使用该程序时的错误:
file must have 'write' attribute
我的程序:
import pickle
inp = input()
if inp == "in":
f = open ("txt.txt", 'wb')
pickle.dump(f, inp)
f.close()
if inp == "out":
f = open ("txt.txt", "rb")
print(pickle.load(f))
f.close()
有谁知道如何解决这个问题吗?
My error when using the program:
file must have 'write' attribute
My program:
import pickle
inp = input()
if inp == "in":
f = open ("txt.txt", 'wb')
pickle.dump(f, inp)
f.close()
if inp == "out":
f = open ("txt.txt", "rb")
print(pickle.load(f))
f.close()
Has anyone an idea how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pickle.dump
函数具有 以下签名:所以文件对象应该是第二个参数。
所以在你的情况下,你会想要:
The
pickle.dump
function has the following signature:So the file object should be the second argument.
So in your case, you would want: