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