keeping local state in an C extension module

Daniel Franke franke.daniel at gmail.com
Thu Jun 30 09:19:44 EDT 2011


2011/6/30 Stefan Behnel <stefan_ml at behnel.de>:
>> If there are too many hoops to jump through to get a reasonable
>> solution working for 2.[567], I might as well go back to
>> Py_InitModule() and static variables. It's somewhat ugly, but it
>> works.
>
> Py2.x has a PyCObject, basically the predecessor to PyCapsule. Writing your
> own little type is another option.

For reference: PyCObject has PyCObject_FromVoidPtr() and
PyCObject_AsVoidPtr() -- exactly what I was looking for (no idea why I
missed it for so long?!). Ok, and it also has the note: "The CObject
API is deprecated as of Python 2.7. Please switch to the new Capsules
API." which is of no concern here :)

Thanks heaps!

     Daniel



More information about the Python-list mailing list