python common built-in module

Common built-in module python
| - os, os.path
| - SYS
| - Random
| - the Math
| - Base64
| - hashlib
HMAC - |
| - Time
| - datetime
......
1, what is the module
definition file XXX.py
2, the classification module
by module creators
| - system built-in modules
| uuid, os, math, random -
module cpython official python interpreter provided
| - third-party modules
| - programmers, organizations, companies,
third-party modules modules need to use, you first need to install the module
| - line installation (easy, provided that there must be net)
PIP install module_name
is to install xxx.py PIP
| - offline installation package
1, first download the offline installation package (xxx.zip)
2, extract the installation package
3, there must be installed in setup.py
. 4, cmd: the install Python setup.py
| - custom module
xxx.py
3, the module import issues
In fact, python modules are placed in the lib folder, which is actually like a library file in java
Here Insert Picture Description
using the keyword import import
import module name
import module name as alias (alias) # use as an alias to do
import xx.xx
such as import the http.server
Here Insert Picture Description
Here Insert Picture Description
import xx.xx AS Alias
from package import module name # python3 strongly recommend this method
4, random module
this module is mainly used to generate random numbers (pseudo-random number)
| - the randint (m, n-) generates a random # integer [m, n-]
| - random () # generates random numbers within a 0 to 1, 1 is not included, the range can be changed by addition, subtraction

Here Insert Picture Description
| - choice () # random screening elements in a sequence (seq) in
Here Insert Picture Description
| - uniform () # random number generated based on normal distribution

Here Insert Picture Description
5, math module
major role math math
| - ceil # ceil
Here Insert Picture Description
| - floor # rounded down
Here Insert Picture Description
Note: global functions of the round rounded #
| - e # NATURAL constant
| - fabs # sum of absolute value, equivalent to the global function ABS ()
Here Insert Picture Description
| - # FMOD modulo
Here Insert Picture Description
| - isnan () # determines a value not a number
Here Insert Picture Description
| - isfinite () # determines whether unlimited
Here Insert Picture Description
| - pi # pi
| - pow () # a power of, equivalent to a global function POW
Here Insert Picture Description
| - sqrt () square root #
Here Insert Picture Description
6, os
| - curdir # os property, to get the current directory, note the relative path to return
Here Insert Picture Description
| - os.path .abspath (os.curdir) # f returns the location of the absolute path
Here Insert Picture Description
| - chdir (path) # change the current directory, path here refers to the path to be modified to
Here Insert Picture Description
| - cpu_count () # returns the cpu core the number of threads corresponding
Here Insert Picture Description
| - getcwd () # get the current directory, note the return of the absolute path
Here Insert Picture Description
| - getpid () # get the current process of the process number
Here Insert Picture Description
| - getppid () # get the programming parent process of the current process

| - kill () # number killed by Processes Processes
| - newline os.linesep # corresponding to the system
Here Insert Picture Description
| - listdir () # returns the documents and files in the corresponding directory folder
Here Insert Picture Description
| - makedirs () # Create a directory to support the multi-layered creation
Here Insert Picture Description
| - mkdir () # create a directory, just create a layer support

| - open () # create the file, equivalent to the global Open
| - pathsep # get delimiter window environment variables; Linux:
Here Insert Picture Description
| - separator sep # path window \ Linux /
| - the Remove (path) # delete a file
| - removedirs () # delete a directory, delete multi-layer support, recursive delete
| - system # execute command terminal

7、os.path

Published 52 original articles · won praise 0 · Views 1126

Guess you like

Origin blog.csdn.net/qq_37244548/article/details/105103601
Recommended