create a new instance in C of a Python subclass

Alex Martelli aleax at
Fri Apr 18 16:07:07 CEST 2003

Paul Miller wrote:

>>You do the same as in Python: call the type.
> How would I do that from C?

To call any Python callable X (where X is a PyObject*) from C,
you can use C/API calls such as PyObject_CallObject, 
PyObject_CallFunction, PyObject_CallFunctionObjArgs.  Any of them 
returns a new reference -- they differ by how you pass parameters.

This holds for any callable Python object X, including of course
types as well as functions and many other kinds.


More information about the Python-list mailing list