How to operate Python modules and functions
This article shows you how to operate Python modules and functions. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Modules and functions
Use the PyImport_Import () function in Python/C API to import the Python module in a C program. The PyImport_Import () function returns a module object. The function prototype is shown below.
PyObject* PyImport_Import (PyObject* name)
The meaning of the parameters is as follows. Name: the name of the module to import. Using the PyObject_CallObject () function in Python/C API and the PyObject_CallFunction () function, you can call functions in Python in a C program. The parameter prototypes are shown below.
PyObject* PyObject_CallObject (PyObject* callable_object, PyObject* args) PyObject* PyObject_CallFunction (PyObject* callable, char * format,...)
For the PyObject_CallObject () function, the arguments mean the following.
Callable_object: the function object to be called.
Args: a list of parameters in tuple form.
For the PyObject_CallFunction () function, the arguments mean the following.
Callable_object: the function object to be called.
Format: specifies the type of parameter.
The argument passed to the function.
Use the
PyModule_GetDict ()
Function to get a list of functions in the Python module.
PyModule_GetDict ()
Function returns a dictionary. The keyword in the dictionary is the function name and the value is the calling address of the function. The function prototype is shown below.
PyObject* PyModule_GetDict (PyObject* module) the above content is how to operate Python modules and functions. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.