Storing a C pointer in a Python class instance

lallous lallous at lgwm.org
Tue Oct 6 17:46:48 CEST 2009


"Carl Banks" <pavlovevidence at gmail.com> wrote in message 
news:d50bba1e-b272-4e39-8a58-377531278abb at z4g2000prh.googlegroups.com...
> On Sep 30, 5:24 am, "lallous" <lall... at lgwm.org> wrote:
>> Hello
>>
>> After using the PyCObject, I cannot pickle the class anymore.
>> Any simple solution to this problem? (or resorting to __reduce__ is the 
>> only
>> solution?)
>
>
> You can't pickle a CObject, you'd have to create a custom type (one
> that implements one of the pickling methods) for that.  Or arrange for
> whatever object contains the CObject to pack and unpack it manually.
>
> Out of curiosity, what kind of data you storing in this CObject?
> Maybe we can help you choose a better way to handle it at the C level.
>
>

I am wrapping a C++ pointer with the python object. That way I can tell with 
which C++ object a given python class instance is associated.

The thing is when developing, I need to pickle but I don't need the C++ 
pointer, so I solved the problem with conditional compilation:
- testing: pickle allowed and "This" is stored in the py object
- production code: no need to pickle and "this" and "pyobject" are bound

Thanks,
Elias 




More information about the Python-list mailing list