One, the benefits of the module
1, Improve maintainability
2, REUSABLE
3, avoid conflicting function names and variable names
Second, the module classification
- Built-in standard module (also known as standard library) execution help (' modules ') View all Python-included modules list
- Third-party open source modules can be installed via the PIP Install Module name Network
- Custom Modules
Third, the module calls
Import module module must be in Sys.path, otherwise will error, Modulenotfounderror:no module named ' ab123 '
From module import sub-modules from a block
From module.xx.xx import xx as yy imports a module from a submodule module and renames
From module Import * Importing a module with caution, may cause variable name and function name conflict
Del module Delete module
Note: Once the module is called, it is equivalent to executing the code in another py file
Iv. Module Lookup Path
import sysprint(sys.path)
Output
[‘‘, ‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip‘, ‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6‘, ‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload‘, ‘/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages‘]
只需要关注第一个当前目录和最后一个site-packages目录,当前目录为入接口程序所在目录
python解释器会按照列表顺序去依次到每个目录下去匹配你要导入的模块名,只要在一个目录下匹配到了该模块名,就立刻导入,不再继续往后找。
https://pypi.python.org/pypi 是python的开源模块库,截止2017年9.30日 ,已经收录了118170个来自全世界python开发者贡献的模块,几乎涵盖了你想用python做的任何事情。 事实上每个python开发者,只要注册一个账号就可以往这个平台上传你自己的模块,这样全世界的开发者都可以容易的下载并使用你的模块。
So how do I download code from this platform?
1. Directly on the above page point download, download, unzip and enter the directory, execute the following command to complete the installation
编译源码 python setup.py build安装源码 python setup.py install
- Install directly from PIP
pip3 install paramiko #parmiko 是模块名
The PIP command automatically downloads the module package and completes the installation.
The software is typically automatically installed in this subdirectory of your Python installation directory
/your_python_install_path/3.6/lib/python3.6/site-packages
PIP command By default will be connected to the foreign official Python server download, slow, you can also use the domestic watercress source, the data will be regularly synchronized foreign official website, a lot faster
-i http://pypi.douban.com/simple/ alex_sayhi --trusted-host pypi.douban.com #alex_sayhi是模块名
Python Basics-Common modules