Python: module definition, import, optimization

Source: Internet
Author: User
1. Definition
Modules: Used to logically organize Python code (variables, functions, classes, logic: Implementing a function), which is essentially the. Py end of Python
File (file name: test.py, corresponding module name: TEST)

2. How to Import
Import Module_name
Import Module1_name,modoule2_name
From Module_alex Import *
From Module_alex import logger as Logger_alex

3.import Nature (Path search and search path)
The essence of the import module is to interpret the Python file again
Import module_name-----> Find the path to module_name, load the file
The essence of the import package is to execute the __init__.py file under the package, and if you want to import other. py files under the package, consider the
__init__.py file with from. import * files under this package

4. Import optimization
For example, there is a module_test.py, the file has a test () function
When import is imported, the test () function is called multiple times, which should be module_test.test (), and each call will find the module file, which is found under the module.
The test () function is too inefficient to use the From Module_test Import test
5. Classification of modules
A. Standard library
B. Open source module (Third party module)
C. Custom Modules

Python: module definition, import, optimization

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.