pickling extension class
harold fellermann
harold.fellermann at upf.edu
Tue Jan 18 14:54:42 EST 2005
On 18.01.2005, at 20:31, Alex Martelli wrote:
> harold fellermann <harold.fellermann at upf.edu> wrote:
>
>> File "/sw/lib/python2.4/pickle.py", line 760, in save_global
>> raise PicklingError(
>> pickle.PicklingError: Can't pickle <type 'hyper.PeriodicGrid'>: it's
>> not found as hyper.PeriodicGrid
>>>>> dir(hyper)
>> ['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__',
>> '__file__', '__name__', 'refcount']
>>>>> hyper.PeriodicGrid
>> <type 'hyper.PeriodicGrid'>
>>
>> So pickle complains about the class PeriodicGrid not being found in
>> the
>> module hyper, but a dir()
>> proves that python can find it. Has anyone an idea what's going wrong
>> here?
>
> These symptomps are pretty weird -- let's try to pin things down a bit
> more. The relevant few lines of pickle.py are:
>
> try:
> __import__(module)
> mod = sys.modules[module]
> klass = getattr(mod, name)
> except (ImportError, KeyError, AttributeError):
> raise PicklingError(
>
> so, could you please edit your pickle.py to provide VASTLY more info,
[...]
> and let us know exactly what his modified pickle.py outputs...?
Here it goes...:
OOPS, error (exceptions.ImportError): No module named hyper
Traceback (most recent call last):
File "pickle_test.py", line 5, in ?
pickle.dump(g,file("test","w"))
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 1387,
in dump
Pickler(file, protocol, bin).dump(obj)
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 231,
in dump
self.save(obj)
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 338,
in save
self.save_reduce(obj=obj, *rv)
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 414,
in save_reduce
save(func)
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 293,
in save
f(self, obj) # Call unbound method with explicit self
File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 765,
in save_global
raise PicklingError(
pickle.PicklingError: Can't pickle <type 'hyper.PeriodicGrid'>: it's
not found as hyper.PeriodicGrid
I have noticed that the error does not occur, when the imported module
('hyper') is in the same directory as the script that pickles. When it
is imported from a subpackage (like in the code
I sent you) it goes wrong.
- harold -
--
Reality is for people who lack imagination.
More information about the Python-list
mailing list