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

Thomas Heller theller at python.net
Sat Dec 28 15:27:44 EST 2002


Tim Peters <tim.one at comcast.net> writes:

> [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.

My ctypes module contains code which works for Python 2.2 and Python 2.3.
Unfortunately the 2.3 version isn't currently up to date, but will be soon.
If you're interested, I can post some examples (hopefully on Monday).

Thomas



More information about the Python-list mailing list