Python: saving objects and using pickle. Error using pickle.dump
Question: 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.


Answer: You have to open your **filehandler** in binary mode, use **wb** instead of
**w** :

    
    
    filehandler = open(b"fruits.obj","wb")
    

