How to create (static|class)-methods from C

Tim Peters tim.one at comcast.net
Fri Dec 27 14:23:21 EST 2002


[Iustin Pop]
> I managed to create a new type from C, and have some methods
> defined with using 'static PyMethodDef a[] {...}', but I don't know
> how could I create a static/class method from C.
> ...

Hold off until Python 2.3.  In 2.3, the C API adds METH_CLASS and
METH_STATIC to the {METH_NOARGS, METH_VARARGS, ...} collection, and it's
easy to write class methods in C then.  datetimemodule.c in current Python
CVS has many examples.  Support for these new options wasn't trivial, and if
you want to do it by hand before 2.3, you'll have to study how support was
added for 2.3.





More information about the Python-list mailing list