Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4685
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: importing class objects from a pickled file |
| Date | 2011-05-05 14:28 +1200 |
| Message-ID | <92egalFbk1U1@mid.individual.net> (permalink) |
| References | <ipq60p$8ps$1@news.jpl.nasa.gov> |
Catherine Moroney wrote: > I am having some problems reading the > object back out, as I get complaints about "unable to import module X". > > The only way I have found around it is to run the read-file code out of > the same directory that contains the X.py file > > Even when I put statements into the code such as "from Y.X import X" ... > the import statement works, but I am still unable to read the object Is the program that reads the pickle file the same one that was used to write it? If not, what might be happening is that the writing program has module X at the top level instead of inside package Y. Then it will get pickled simply under the name "X" instead of "Y.X", and the reading program will expect to find it at the top level as well. It's important that the reading and writing programs agree about the location of the pickled classes in the package namespace, unless you take steps to customise the pickling process. -- Greg
Back to comp.lang.python | Previous | Next — Previous 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