Jump to content


Photo

Pickle Module


  • Please log in to reply
1 reply to this topic

#1 Sunny219

Sunny219

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 June 2014 - 04:06 AM

Hi guys,

When I learn Head First Python book to p134 . Here is the code:

import pickle

try:
with open('man_data.txt','wb') as man_file:
pickle.dump(man, man_file)
with open('other_data.txt', 'wb') as other_file:
pickle.dump(other, other_file)

except IOError as err:
print('File error: '+str(err))

except pickle.PickleError as perr:
print('Pickling error: '+str(perr))

however, when I run the code, something is wrong like this:

>>>
Traceback (most recent call last):
File "/Users/shijun/Documents/HeadFirstPython/chapter4/sketch10.py", line 5, in <module>
pickle.dump(man, man_file)
NameError: name 'man' is not defined.

Can you help me out? Thanks a lot.

#2 Sunny219

Sunny219

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 June 2014 - 05:16 PM

I fixed it, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users