Pickling extension types
Stefan Kuzminski
stefan.kuzminski at gmail.com
Tue May 3 22:28:51 EDT 2011
closer I think
1) I changed tp_name to be 'observation.MV' ( module is named observation.c
) and now I get a new error..
PicklingError: Can't pickle <type 'observation.MV'>: import of module
observation failed
2) here is the init function, sorry I did not include it in the original
listing
void initobservation(void) {
PyObject *m;
m = Py_InitModule("observation", observation_methods);
Py_INCREF(&PyMV_Type);
PyModule_AddObject(m, "MV", (PyObject *)&PyMV_Type);
}
thx,
S
On Tue, May 3, 2011 at 6:05 PM, Robert Kern <robert.kern at gmail.com> wrote:
> On 5/3/11 4:34 PM, Stefan Kuzminski wrote:
>
>> Thanks for the clues, I made a modification so that reduce returns this..
>>
>> return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None,
>> Py_None, Py_None );
>>
>> and now I get this different error when trying to pickle the type..
>>
>> ----------------------------------------------------------------------
>> Traceback (most recent call last):
>> File "test_missing.py", line 16, in test
>> print cPickle.dumps( mv )
>> PicklingError: Can't pickle <type 'MV'>: attribute lookup __builtin__.MV
>> failed
>>
>
> You need to do two things:
>
> 1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name
> of your extension module.
>
> 2. Make sure that you add the type object to your module's namespace.
>
> PyMODINIT_FUNC
> initmymodule(void) {
> ...
> Py_INCREF(&PyMV_Type);
> PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type);
> }
>
> C.f.
>
> http://docs.python.org/extending/newtypes.html
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma
> that is made terrible by our own mad attempt to interpret it as though it
> had
> an underlying truth."
> -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110503/55a908a3/attachment-0001.html>
More information about the Python-list
mailing list