Modules: Code to implement a function of the code set, functional modularity, save time, improve efficiency
First, the module import
The import module, in fact, tells the Python interpreter to explain the corresponding. py file
• Import the. py file, and the interpreter interprets the. py file
• Pour a package that explains the package under the __init__.py file
To import a module method:
1 Import Time 2 from Import Sleep 3 from Import Sleep as SP 4 from Import *
The path to the import module, which is Sys.path
1 ImportSYS2 Print(Sys.path)3 4 #The results are as follows5['C:\\users\\lenovo\\pycharmprojects\\ethan\\study_day7','C:\\users\\lenovo\\pycharmprojects\\ethan','C:\\python35\\python35.zip','C:\\python35\\dlls','C:\\python35\\lib','c:\\python35','c:\\python35\\lib\\site-packages']
If you don't have the path you want, use Sys.path.append (' path ') to add
Various catalogs can be obtained through the OS module, such as:
1 Import SYS 2 Import OS 3 4 Pre_path = Os.path.abspath ('./')5# Print (Pre_path)6 sys.path.append (Pre_path)
Second, the classification of the module
Custom modules: Personal writing, making calls in code you write
Built-in modules: Python official offers
Open Source module: Third-party authoring, open source download installation use
Download the installation method:
12pip3 apt-get
1 Download Source code 2 Decompression Source 3 Go to Catalog 4 compiled source python setup.py build5 installation source python setup.py install
Method Two
Introduction to the Python module