Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4595
| Return-Path | <prologic@shortcircuit.net.au> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'wed,': 0.04; 'received:209.85.213.46': 0.07; 'received:mail- yw0-f46.google.com': 0.07; 'see:': 0.07; 'to:name:python list': 0.09; 'am,': 0.14; 'wrote:': 0.14; '"from': 0.16; '(say': 0.16; 'succeeds,': 0.16; 'top,': 0.16; 'class,': 0.16; 'subject:file': 0.16; 'suggest': 0.19; 'code,': 0.20; 'code': 0.22; 'header:In- Reply-To:1': 0.22; 'received:209.85.213': 0.23; 'objects': 0.24; 'statement': 0.26; 'object': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'class': 0.29; "won't": 0.30; 'loads': 0.31; 'solved': 0.31; 'does': 0.31; 'url:library': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'url:docs': 0.33; 'data.': 0.33; 'file': 0.35; 'fails': 0.35; 'error.': 0.36; 'received:209.85': 0.37; 'url:python': 0.37; 'received:google.com': 0.38; 'user': 0.38; 'but': 0.38; 'url:org': 0.38; 'though': 0.38; 'unless': 0.38; 'common': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; '2011': 0.62; 'subject:class': 0.84 |
| MIME-Version | 1.0 |
| In-Reply-To | <ipq60p$8ps$1@news.jpl.nasa.gov> |
| References | <ipq60p$8ps$1@news.jpl.nasa.gov> |
| From | James Mills <prologic@shortcircuit.net.au> |
| Date | Wed, 4 May 2011 12:29:53 +1000 |
| Subject | Re: importing class objects from a pickled file |
| To | python list <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1138.1304476217.9059.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1304476217 news.xs4all.nl 34849 [::ffff:82.94.164.166]:40289 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4595 |
Show key headers only | View raw
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