Hi all,
I have a problem pickling an extension class. As written in the
Extending/Embedding Manual, I
provided a function __reduce__ that returns the appropreate tuple. This
seams to work fine,
but I still cannot pickle because of the following error:
[color=blue][color=green][color=darkred]
>>> from model import hyper
>>> g = hyper.PeriodicG rid(4,4,1)
>>> g.__reduce__()[/color][/color][/color]
(<type 'hyper.Periodic Grid'>,(4.,4.,1 .))[color=blue][color=green][color=darkred]
>>> import pickle
>>> pickle.dump(g,f ile("test","w") )[/color][/color][/color]
Traceback (most recent call last):
File "pickle_test.py ", line 5, in ?
pickle.dump(g,f ile("test","w") )
File "/sw/lib/python2.4/pickle.py", line 1382, in dump
Pickler(file, protocol, bin).dump(obj)
File "/sw/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
File "/sw/lib/python2.4/pickle.py", line 338, in save
self.save_reduc e(obj=obj, *rv)
File "/sw/lib/python2.4/pickle.py", line 414, in save_reduce
save(func)
File "/sw/lib/python2.4/pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "/sw/lib/python2.4/pickle.py", line 760, in save_global
raise PicklingError(
pickle.Pickling Error: Can't pickle <type 'hyper.Periodic Grid'>: it's
not found as hyper.PeriodicG rid[color=blue][color=green][color=darkred]
>>> dir(hyper)[/color][/color][/color]
['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__',
'__file__', '__name__', 'refcount'][color=blue][color=green][color=darkred]
>>> hyper.PeriodicG rid[/color][/color][/color]
<type 'hyper.Periodic Grid'>
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?
Any help appreceated,
- harold -
--
What is mind? -- Doesn't matter.
What is matter? -- Never mind!
--
I have a problem pickling an extension class. As written in the
Extending/Embedding Manual, I
provided a function __reduce__ that returns the appropreate tuple. This
seams to work fine,
but I still cannot pickle because of the following error:
[color=blue][color=green][color=darkred]
>>> from model import hyper
>>> g = hyper.PeriodicG rid(4,4,1)
>>> g.__reduce__()[/color][/color][/color]
(<type 'hyper.Periodic Grid'>,(4.,4.,1 .))[color=blue][color=green][color=darkred]
>>> import pickle
>>> pickle.dump(g,f ile("test","w") )[/color][/color][/color]
Traceback (most recent call last):
File "pickle_test.py ", line 5, in ?
pickle.dump(g,f ile("test","w") )
File "/sw/lib/python2.4/pickle.py", line 1382, in dump
Pickler(file, protocol, bin).dump(obj)
File "/sw/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
File "/sw/lib/python2.4/pickle.py", line 338, in save
self.save_reduc e(obj=obj, *rv)
File "/sw/lib/python2.4/pickle.py", line 414, in save_reduce
save(func)
File "/sw/lib/python2.4/pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "/sw/lib/python2.4/pickle.py", line 760, in save_global
raise PicklingError(
pickle.Pickling Error: Can't pickle <type 'hyper.Periodic Grid'>: it's
not found as hyper.PeriodicG rid[color=blue][color=green][color=darkred]
>>> dir(hyper)[/color][/color][/color]
['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__',
'__file__', '__name__', 'refcount'][color=blue][color=green][color=darkred]
>>> hyper.PeriodicG rid[/color][/color][/color]
<type 'hyper.Periodic Grid'>
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?
Any help appreceated,
- harold -
--
What is mind? -- Doesn't matter.
What is matter? -- Never mind!
--
Comment