Jump to content


Photo

Excpetion Error On Page 224?


  • Please log in to reply
1 reply to this topic

#1 fokker

fokker

    Active Member

  • Members
  • PipPip
  • 12 posts
  • Gender:Male
  • Location:Madrid (Spain)

Posted 13 April 2011 - 01:13 AM

Why proposed solution of get_coach_data & get_from_store functions on page 224 includes an IOError exception?. Would it be better?:
except pickle.PickleError as perr
       print('Pickling error: '+ str(perr))


Regards,

#2 paulbarry

paulbarry

    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 307 posts

Posted 19 April 2011 - 05:16 AM

I don't think so, as the IOError code is catching a potential failure of the call to the open() function. The fact that we are opening a pickle file is not important to open() as we could be opening *any* file type. Now, having said that, it probably makes sense to wrap the call to pickle.dump() and pickle.load() in a try block (as you suggest), just in case something was to go wrong while writing or reading the pickled data from the file, although that might be overkill. See page 134 for another possible example usage.

Regards.

--Paul.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users