How to get the Callable of builtin functions

Brian Quinlan BrianQ at ActiveState.com
Wed Sep 26 17:24:28 EDT 2001


> Hi,
>
> This question is about embedding Python in C.
> Does anyone know how to obtain a callable PyObject of the system
> built-in functions, like "print" and "exec"?
> I tried:
> PyObject *m = PyImport_AddModule(__main__);
> PyObject *func = PyObject_GetAttrString(m, "print");

"print" and "exec" are not functions, they are operators. There are C
API functions to use those operators e.g. PyObject_Print.

Cheers,
Brian





More information about the Python-list mailing list