How To Call A Python Function By Name From The C-API?
From the c-api, I would like to call a python function by name. I would then be calling the function with a list of python objects as arguments. It is not clear to me in the Pytho
Solution 1:
Basically, you use the Python C API to get the module the function is contained in, then query the module dictionary for the function. That's more or less the same what the Python runtime does internally when your Python code invokes a function from somewhere.
Relevant functions from the API to look at are PyImport_ImportModule
, PyModule_GetDict
, PyDict_GetItem
and the PyObject_CallXXX
family of functions.
Post a Comment for "How To Call A Python Function By Name From The C-API?"