Defining *class* methods on C code

Thomas Heller theller at python.net
Thu Feb 5 15:03:59 EST 2004


I once knew how to do it, but I cannot find or remember it anymore:

How can I attach *class* methods to a type in C code, when I have a
function

PyObject *func(PyObject *type, PyObject *arg);

with the METH_O calling convention?  The type is already created, I
cannot insert it into the tp_methods array anymore.

Something like this:

class X(object):
    pass

def func(cls, arg):
    ....

X.func = classmethod(func)

Thanks,

Thomas



More information about the Python-list mailing list