One, the Python module
The power of Python is that he has a very rich and powerful library of standards and third-party libraries , and almost any feature you want to implement has the appropriate Python library support
The Python module, which is a python file that ends with a. Py, contains Python object definitions and Python statements.
Use a module to avoid conflicting function names and variable names. Functions and variables of the same name can exist in separate modules
The modules are divided into three types:
- built-in modules : sys, OS, subprocess, time, JSON, etc.
- Custom Modules : When customizing a module, be careful about naming it and not conflict with the module name that comes with Python. For example, the system comes with a
sys
module, its own module can not be named sys.py
, or you will not be able to import the system's own sys
module.
- Open Source Modules : Public third-party modules, such as Https://pypi.python.org/pypi. Can be installed using PIP install, similar to Yum installation software
>>> Help (' modules ')
See all modules in Python
Import Statement
Once the module is well defined, we can use the import statement to introduce the module with the following syntax:
import module1[, module2[,... Modulen]
When you invoke a function in a module, you must refer to this: module name. function name
When the interpreter encounters an import statement, the module is imported if it is in the current search path.
A search path is a list of all directories that an interpreter will search first. To import the module support.py, you need to place the command at the top of the script:
Module name. function name
Python2-Base 2