1, Module Introduction
Many functions are grouped by category and placed in separate files. In Python, a. py file is called a module. In other languages, it is called a class library.
What are the benefits of using modules?
(1) Greatly improve the maintainability of the Code;
(2) Writing code does not have to start from scratch.
Categories of modules:
Built-in modules, third-party modules, automatic modules.
2. Import Module
Modules should be imported first, then used.
(1) Import module method
Import Module from import xx # points represent the folder hierarchy. You can import only one of these functions. from import xx as rename # Specify an alias for the imported module from Import * # Import all the functions in the module
(2) Search path
the Import module actually tells the Python interpreter to explain the py file. When the module is imported, it is based on the sys.path path from top to bottom, and once it is found, it is imported and stopped for searching.
ImportSYSPrint(Sys.path) The result is: ['c:\\users\\sea\\pycharmprojects\\untitled', 'c:\\users\\sea\\pycharmprojects\\untitled', 'C:\\users\\sea\\appdata\\local\\programs\\python\\python36-32\\python36.zip', 'C:\\users\\sea\\appdata\\local\\programs\\python\\python36-32\\dlls', 'C:\\users\\sea\\appdata\\local\\programs\\python\\python36-32\\lib', 'c:\\users\\sea\\appdata\\local\\programs\\python\\python36-32', 'c:\\users\\sea\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages'] #这是第三方模块
If the Sys.path path list does not have the path you want, it can be added by Sys.path.append (' path ').
such as: sys.path.append ("e:\\") will also add the E-disk to the directory
3, third-party module installation
(1) Installation with PIP3
The PIP3 is already installed in the Python3. You can see it under the Python installation directory Scripts folder.
The PIP tool in Python2 needs to be installed first.
Example: Installing the Requests module PIP3 install requests
(2) Source code installation
① first download the source code (tar file), unzip to find the setup.py file
②CD switch to this extract directory, execute command: Python setup.py install
Python Basics-Modules