Practical application of Python modules and functions

Source: Internet
Author: User

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.

 
 
  1. 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.

 
 
  1. PyObject* PyObject_CallObject( PyObject *callable_object, PyObject *args)  
  2. 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

 
 
  1. PyModule_GetDict() 

Function to obtain the function list in the Python module.

 
 
  1. 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.

 
 
  1. PyObject* PyModule_GetDict( PyObject *module)  

Introduction to the Python module and function-related practical application solutions.

· Edit recommendations]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.