Python class method as an argument of a function in a C extension

mauro mauro.tiz at gmail.com
Thu Sep 27 02:32:28 EDT 2007


On 26 Set, 19:00, Matimus <mccre... at gmail.com> wrote:
> > Can anybody give me an hint (or some link) on how to define
> > 'aCFunction' and how to call 'self.myMethod' in the C source code?
>
> A python function defined in C accepts a pointer to self and a tuple
> of arguments, each of which is also a PyObject. If you pass a function
> or method, it will be included in the tuple of arguments. I don't
> think there is any difference between passing a method and a function.
> You can call that method using functions in the `Object Protocol'
> section of the API, such as PyObject_Call(...).
>
> Here is an example from the Python documentation:http://docs.python.org/ext/callingPython.html
>
> The first part shows how to get a function as an argument. The
> following bits of code show how to actually call that function.The
> example uses PyEval_CallObject, which I can't find documentation to.
> I'm not sure if it even exists (it may be a documentation error). But
> from the example it seems to work exactly the same as
> PyObject_CallObject.
>
> Matt

Thanks a lot!
At last I succeeded in finding an example:
http://mail.python.org/pipermail/python-list/1999-May/003441.html
This uses exactly the PyObject_CallObject, as you suggest.

Mauro




More information about the Python-list mailing list