One, module, package
What is a module?
The module is essentially a Python file, which is used to organize the code, meaning that the Python code is written inside, the filename is the name of the module, test.py test is the module name.
What is a package?
Packages, the package is essentially a folder, and the folder is not the same is that it has a __init__.py file, the package is logic to organize the module, that is, it is used to store modules, if you want to import the modules in other directories, then this directory must be a package to be imported.
Import Module
The essence of the import module is to take the Python file and execute it once.
Using the modules in the package requires the from in the __init__.py file. Import xxx
Module Categories:
Standard library: Python built-in
Open Source module: third party
Custom module: Write it by yourself
Second, OS, sys module
Third, random module
Four, Time&datetime module
Time and datetime modules are primarily used for operation times
There are three ways to represent time, one is timestamp, one is format time, one is time tuple
Five, shelve module
Shelve module is used to persist data storage, compared to JSON, JSON can only store list, dictionary such data type, if it is a function, a class, there is no way to store, but shelve module can, shelve module is Key-value storage, Value is the content you store, using the following:
Vi.. Hashlib Module
Hashlib module, mainly used for encryption related operations, in the Python3 version, instead of the MD5 and SHA modules, mainly provides SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm.
Seven, Configparser module
The Configparser module is used to manipulate configuration files for generating and modifying common configuration documents, and Python 3.x is configparser in Configparser,python2.
A common configuration file is as follows:
What if you want to use Python to generate a document like this?
Here are some common operations, modifying, adding, deleting nodes, attributes
Eight, re module
The RE module is a regular expression module that is used to match some specific strings.
Common Regular Expression symbols
Common syntax for matching
Python Common Modules