When I try to pickle something, I get an AttributeError: 'str' object has no attribute 'write'
AttributeError: 'str' object has no attribute 'write'
An example:
import pickle pickle.dump({"a dict":True},"a-file.pickle")
produces:
... AttributeError: 'str' object has no attribute 'write'
What's wrong?
It's a trivial mistake: pickle.dump(obj,file) takes a file object, not a file name.
pickle.dump(obj,file)
file
What I need is something like:
with open("a-file.pickle",'wb') as f: pickle.dump({"a dict":True},f)
2.1m questions
2.1m answers
60 comments
57.0k users