How to better pickle an extension type
- From: "dgdev" <dgdev3141@xxxxxxxxx>
- Date: 16 Apr 2007 08:18:42 -0700
I would like to pickle an extension type (written in pyrex). I have
it working thus far by defining three methods:
class C:
# for pickling
__getstate__(self):
... # make 'state_obj'
return state_obj
__reduce__(self):
return C,(args,to,__init__),me.__getstate__()
# for unpickling
__setstate__(self,state_obj):
self.x=state_obj.x
...
This gets the class pickling and unpickling.
However, I'd like to not specify arguments for __init__ (as I do now
in __reduce__), and so not have __init__ invoked during unpickling.
I would like to have the pickling machinery somehow create an
uninitialized object, and then call its __setstate__, where I can re-
create it from 'state_obj'.
Is there a kosher way to do so, that is without me having to have a
special mode in the constructor for when the object is being created
by the unpickler?
.
- Follow-Ups:
- Re: How to better pickle an extension type
- From: Ziga Seilnacht
- Re: How to better pickle an extension type
- From: Alex Martelli
- Re: How to better pickle an extension type
- Prev by Date: Re: Writing Log CSV (Efficiently)
- Next by Date: Python and SSL
- Previous by thread: Re: Writing Log CSV (Efficiently)
- Next by thread: Re: How to better pickle an extension type
- Index(es):
Relevant Pages
|