Return-Path: 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: References: From: James Mills Date: Wed, 4 May 2011 12:29:53 +1000 Subject: Re: importing class objects from a pickled file To: python list 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, May 4, 2011 at 10:18 AM, Catherine Moroney wrote: > Am I explaining myself properly? =C2=A0Why doesn't the code that loads th= e > object from the pickled file work unless I am sitting in the same directo= ry? > =C2=A0 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 --=20 -- James Mills -- -- "Problems are solved by method"