Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4595
| References | <ipq60p$8ps$1@news.jpl.nasa.gov> |
|---|---|
| From | James Mills <prologic@shortcircuit.net.au> |
| Date | 2011-05-04 12:29 +1000 |
| Subject | Re: importing class objects from a pickled file |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1138.1304476217.9059.python-list@python.org> (permalink) |
On Wed, May 4, 2011 at 10:18 AM, Catherine Moroney <Catherine.M.Moroney@jpl.nasa.gov> wrote: > Am I explaining myself properly? Why doesn't the code that loads the > object from the pickled file work unless I am sitting in the same directory? > The code that writes the pickled file has the statement > "from Y.X import X" statement" at the top, as does the reading code, but > even though that import statement succeeds, the read still fails with the > import error. pickled objects won't work this way unless you "customize" the way in which your class gets serialized. See: http://docs.python.org/library/pickle.html#the-pickle-protocol Any time you want to unpickle a user class, that class must be available. I suggest serializing to a more common format (say JSON) and re-create your class with the data. cheers James -- -- James Mills -- -- "Problems are solved by method"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
importing class objects from a pickled file Catherine Moroney <Catherine.M.Moroney@jpl.nasa.gov> - 2011-05-03 17:18 -0700 Re: importing class objects from a pickled file James Mills <prologic@shortcircuit.net.au> - 2011-05-04 12:29 +1000 Re: importing class objects from a pickled file Owen Jacobson <angrybaldguy@gmail.com> - 2011-05-04 01:29 -0400 Re: importing class objects from a pickled file Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-05 14:28 +1200
csiph-web