Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
import pickle


hello="hello"

pickle.dump(open('file.txt', 'wb'), hello)

print (hello)



hi=pickle.load(open('file.txt', 'rb'))

print (hi)


This gets me the error:
VB
File "/home/ubuntu/workspace/tests.py", line 7, in <module>
    pickle.dump(open('file.txt', 'wb'), hello)
TypeError: file must have a 'write' attribute


How do I fix this? Thanks
Posted

1 solution

Hi change it to
pickle.dump(hello,open('file.txt', 'wb'))
 
Share this answer
 
Comments
Blake Allen 16-Mar-15 19:50pm    
Oooh, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900