pickling extension class

Alex Martelli aleaxit at yahoo.com
Tue Jan 18 14:31:40 EST 2005


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,
say:

        try:
            print 'Here it goes...:'
            _xx = __import__(module)
            print '  __import__ says: %r' % (_xx,)
            mod = sys.modules[module]
            print '  in sys.modules: %r' % (mod,)
            klass = getattr(mod, name)
            print '  klass is: %r' % (klass,)
        except (ImportError, KeyError, AttributeError), _xx:
            print '  OOPS, error (%s): %s' % (_xx.__class__, _xx)
            raise PicklingError(

and let us know exactly what his modified pickle.py outputs...?


Thanks,

Alex



More information about the Python-list mailing list