0

To create a class usable in Python is pretty straight-forward: http://code.activestate.com/recipes/54352-defining-python-class-methods-in-c/

But how to make methods static?

Nicu Tofan
  • 1,052
  • 14
  • 34

1 Answers1

1

Use the METH_STATIC flag in PyMethodDef. The method will be passed NULL as the first parameter rather than an instance of the type.

static PyMethodDef FooMethods[] = 
{
    {"__init__", Foo_init, METH_VARARGS, 
     "doc string"},
    {"doSomething", Foo_doSomething, METH_VARARGS | METH_STATIC,
     "doc string"},
    {NULL},
};
Janne Karila
  • 24,266
  • 6
  • 53
  • 94