1. Modules (variables, functions, classes, implements a function)
Package: Used to logically organize the module, essentially a directory (must have __init__.py)
2. How to Import
Import Module_alex
From Module_alex Import *
From Modele_alex import logger, running
From Modele_alex import 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 test test = ' test.py All code ')
From test Import name = Test.name All code
Import Module_name is looking for a copy of the module in Sys.path
The essence of importing packages is to execute __init__.py
4. Import optimization from module_test Import test
5. Module classification
Standard library
Open source Module
Custom Modules
Before the import module, you need to add a path within the module that is not in the same directory
Import Os,sys
Print (Os.path.abspath (__file__)) #打印当前文件路径
Os.path.dirname (Os.path.abspath (__file__)) #返回上一级路径
Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) #返回上上层路径
Sys.path.append (Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) #路径的临时添加
If it is the same directory can be added directly
Python module description