1. Definition
A python module is a .py file. A module can have multiple functions. When using a module, you only need to import to use the functions in the module. The process of importing the module is equivalent to executing everything in the py file.
There are three types of opython modules: 1. Self-contained modules, such as random, os, time 2. Third-party modules, which need to be downloaded and installed before they can be called 3. Modules written by themselves
Second, the use of modules
1. Self-contained module
When using the built-in module, you only need to import it
import datetime #import print(datetime.datetime.today()) #使用
2. Third-party modules
If a third-party module is used, it must be installed first. There are 2 ways to install:
(1) Online installation, fool installation
Enter pip install pymysql in the operating system console to automatically download the pymysql module and install it.
(2) Offline press installation
The prerequisite for offline installation is that the software package has been downloaded. To download the software package, you need to search for the desired software report name in Baidu, such as pymysql
Click to enter the download, there are two file formats, both .whl and tar.gz
After the download is complete, for the installation package at the end of whl, enter pip install xxx.whl in the console (xxx.whl refers to the full name of the downloaded file)
Installation package ending with tar.gz:
1. Unzip
2. Go to the unzipped folder
3. Open the command line and enter python setup.py install
Ready to use after installation
3. Custom modules
When python imports a module, it will first go to the current directory to find it. If it cannot be found, it will go to the python environment variable to find it again (python environment variable view, sys.path). The python file written by yourself, if you want to import and use it, Must be placed in the current directory or in the python environment variable.