Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4579 > unrolled thread
| Started by | Robert Kern <robert.kern@gmail.com> |
|---|---|
| First post | 2011-05-03 17:05 -0500 |
| Last post | 2011-05-03 17:05 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Pickling extension types Robert Kern <robert.kern@gmail.com> - 2011-05-03 17:05 -0500
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2011-05-03 17:05 -0500 |
| Subject | Re: Pickling extension types |
| Message-ID | <mailman.1126.1304460339.9059.python-list@python.org> |
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
Back to top | Article view | comp.lang.python
csiph-web