Class data members in C

Ziga Seilnacht ziga.seilnacht at gmail.com
Tue Jan 16 18:39:37 EST 2007


Nick Maclaren wrote:
> Hmm.  The extensions documentation describes how to add instance
> members to a class (PyMemberDef), but I want to add a class member.
> Yes, this is constant for all instances of the class.
>
> Any pointers?

Add something like this to your PyMODINIT_FUNC after you have
initialized your type with PyType_Ready:

PyDictSetItemString(YourType.tp_dict, "attrname", attrvalue);

Ziga




More information about the Python-list mailing list