Python: saving objects and using pickle. Error using pickle.dump
Posted
by
Peterstone
on Stack Overflow
See other posts from Stack Overflow
or by Peterstone
Published on 2010-12-25T12:50:37Z
Indexed on
2010/12/25
12:54 UTC
Read the original article
Hit count: 343
Hello I have an Error and I don´t the reason:
>>> class Fruits:pass
...
>>> banana = Fruits()
>>> banana.color = 'yellow'
>>> banana.value = 30
>>> import pickle
>>> filehandler = open("Fruits.obj",'w')
>>> pickle.dump(banana,filehandler)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
TypeError: must be str, not bytes
>>>
I don´t know how to solve this error because I don´t understand it. Thank you so much.
© Stack Overflow or respective owner