Hailiang Zhang
Hailiang Zhang

Reputation: 18870

How to pass a python object to C extension and call its method inside?

say I have a python object "o" with a method "m()", and I want to pass it as:

PyObject *f(PyObject *self, PyObject *args)
{
  PyObject *o;
  PyArg_ParseTuple(args, "O", &o);
  //o.m();
}

Apparently the last commented line doesn't compile, and I wonder whether there is a way I can achieve this.

Upvotes: 2

Views: 730

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

You want PyObject_CallMethod().

Upvotes: 5

Related Questions