1. Definition:
A module used to logically organize Python code (variables, functions, classes, logic: Implementing a function), essentially the. PY result of the Python file (file name: test.py corresponding module name: TEST) Package: It is used to logically organize the module, which is essentially a directory ( Must have a __init__.py file)
2. How to Import
Import module_name #导入一个模块import module_name,module2_name #导入多个模块from module_name Import * #定义导入模块下所有的方法导入 Operation not recommended) from MODULE_NAME import M1 m2 m3from module_name 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 once (import Test test= ' test.py All code ' defines a variable test, which points to the area of memory) (from test import name name= ' code ') IM Port module_name----->module_name.py Path--->sys.path-----the >module_name.py
The essence of the import package is to execute the __init__.py file under the package
4. Import optimization
From module_name import test as Test_one #执行导入模块test, import once, use the test method multiple times
5. Classification of modules:
A: standard library B: Open source module C: Custom module
Python basic 5 common modules