The Python module is also widely used in the application of computer languages. The following article introduces the Python module in practical application, the following is a detailed description of the article, and I hope you will learn from it.
Modules and functions
You can use the PyImport_Import () function in the Python/c api to import the Python module to the C program. The PyImport_Import () function returns a module object. The function prototype is as follows.
- PyObject* PyImport_Import( PyObject *name)
The parameter meanings are as follows. Name: name of the module to be imported. Using the PyObject_CallObject () and PyObject_CallFunction () functions in Python/C APIs, you can call functions in Python in C Programs. The parameter prototypes are as follows.
- PyObject* PyObject_CallObject( PyObject *callable_object, PyObject *args)
- PyObject* PyObject_CallFunction( PyObject *callable, char *format, ...)
For the PyObject_CallObject () function, the parameter meanings are as follows.
Callable_object: The function object to be called.
Args: list of parameters in the format of tuples.
The parameter meanings of PyObject_CallFunction () are as follows.
Callable_object: The function object to be called.
Format: Specifies the parameter type.
Parameters passed to the function.
Use
- PyModule_GetDict()
Function to obtain the function list in the Python module.
- PyModule_GetDict()
The function returns a dictionary. The keyword in the dictionary is the function name and the value is the call address of the function. The function prototype is as follows.
- PyObject* PyModule_GetDict( PyObject *module)
Introduction to the Python module and function-related practical application solutions.
· Edit recommendations]