[Tutor] TypeError: Need Help

Ali Sina seena_blk at yahoo.com
Thu Nov 19 11:28:02 CET 2009


>>I have Python 3.0 and I'm trying to learn from a pdf document. I followed its instructions >>but I've encountered a problem in its Pickling chapter. This is the code I've written:

import pickle, shelve

print('Pickling list.')
variety=['sweet','hot','dill']
shape=['whole','spear','chip']
brand=['Claussen','Heinz','Vlassic']

pickle_file=open('pickles1.dat','w')
pickle.dump(variety, pickle_file)
pickle.dump(shape, pickle_file)
pickle.dump(brand, pickle_file)
pickle_file.close()

print('\nUnpickling list.')
pickle_file=open('pickles1.dat','r')
variety=pickle.load(pickle_file)
shape=pickle.load(pickle_file)
brand=pickle.load(pickle_file)
print(variety,'\n',shape,'\n',brand)
pickle_file.close()

>>But it gives this error:

Traceback (most recent call last):
  File "E:/Python/pickle it.py", line 11, in <module>
    pickle.dump(variety, pickle_file)
  File "C:\Python31\lib\pickle.py", line 1354, in dump
    Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
TypeError: write() argument 1 must be str, not bytes

>>I read Python Docs but it didn't help me either. I hoping anyone of you could guide me or >>send the revised code itself. Thank you.

>>Regards



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091119/38c76e68/attachment.htm>


More information about the Tutor mailing list