Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: importing class objects from a pickled file Date: Thu, 05 May 2011 14:28:34 +1200 Lines: 27 Message-ID: <92egalFbk1U1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net uC/r+V8s7WMhIVk1ITs9/wP3GLnu0g2HUOzp2z8rEZxH9hySE/ Cancel-Lock: sha1:t2vy4zwIwPc3wxOfzqmCJOfAQpg= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4685 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