A. Serialization Module
1.Json
2.pickle
3.shelve
B. Hashlib Module (Digest algorithm)
C. Configparser Module
D. Logging module
E. Collections Module
F. Random Module
G. Time Module
Time.sleep (sec) # (thread) sleeps the specified number of seconds.
1 O'Clock stamp: (Test execution efficiency)
The time stamp representation is the offset that is calculated in seconds from 00:00:00, January 1, 1970, in Greenwich.
data type: float
time.time ()
2 structured time: type similar to Namedtuple (intermediate between timestamp and format time string, which can be used to convert between the two)
Time.localtime () structured time for the current time zone
Time.gmtime () structured time in the London time zone
3 Format Time string: (Time for human viewing)
time.strftime ('%y-%m-%d%h:%m:%s ')
4 Conversions
1 timestamp turns into formatted time string
time_stamp = Time.time ()
struct_time = Time.localtime (time_stamp)
strformat_time = Time.strftime ('%y-%m-%d%h:%m:%s ', struct_time)
print (strformat_time)
One Step
strformat_time = Time.strftime ('%y-%m-%d%h:%m%s ' Time.localtime (Time.time ()))
2 Format time string to timestamp
strformat_time = Time.strftime ('%y-%m-%d%h:%m:%s ')
struct_time = Time.strptime (Strformat_time, '%y-%m-%d%h:%m:%s ')
time_stamp = Time.mktime (struct_time)
print (time_stamp)
One Step
time_stamp = Time.mktime (Time.strptime (Time.strftime ('%y-%m-%d%h:%m%s '), '%y-%m-%d%h:%m:%s ' )
localtime (T_stamp)
gmtime (T_stamp) strftime ('%y-%m-%d%h:%m%s ', st_time)
t_stamp------------------>st_time------------------------------------->strf_time
strptime (strf_time, '%y-%m-%d%h:%m:%s ') mktime (st_time)
strf_time--------------------------------------->st_time---------------->t_stamp
5 timestamp goes directly to format time
str_time = Time.ctime (Time.time ())
6 structured time turns into formatted time
str_time = Time.asctime (Time.localtime ())
H. OS module: an interface that interacts with the operating system
Absolute path: The path from the root to the destination file.
Relative path: The path from the current location to the destination file.
Working directory, parent directory, current directory: the absolute path to the folder where the file resides.
OS.GETCWD () #获取文件的挡墙工作目录 * * * *
Os.chdir () #相当于shell的cd
Os.curdir #返回当前位置 ('. ')
Os.pardir #放回上级目录位置 (' ... ')
1. and folder-related
Os.mkdir () #一次创建一个文件夹 * * *
Os.makedirs () #递归创建文件夹 * * *
Os.rmdir () #一次删除一个文件夹, you cannot delete a folder if it is not empty
Os.removedirs () #递归删除文件夹
Os.listdir () #列出指定目录下的所有文件和子目录, including hidden files, returned as a list * * *
2. and file-related
Os.remove () #删除一个文件
Os.rename () #重命名
Os.stat () #获取文件/directory information
3. Path series and Paths related
Os.path.abspath (PATH) # returns the path normalized absolute path * * *
Os.path.split (path) # divides path into directories and file names and returns as tuples * * *
Os.path.dirname (Path) #返回path的目录. is actually the first element of Os.path.split (path)
Os.path.basename (Path) #返回path最后的文件名. How path ends with/or \ Returns a null value, which is the second element of Os.path.split (path).
Os.path.exists (path) #如果path存在, returns True if path does not exist, returns false
Os.path.isabs (path) #如果path是绝对路径, returns True
Os.path.isfile (path) #如果path是一个存在的文件, returns True. otherwise returns false
Os.path.isdir (path) #如果path是一个存在的目录, returns True. Otherwise, return Fals
Os.path.join (path1[, path2[, ...]) #拼接路径. When you combine multiple paths, the parameters before the first absolute path are ignored. * * *
Os.path.getatime (PATH) #最后的访问时间
Os.path.getmtime (PATH) #最后的修改时间
Os.path.getsize (PATH) #path的大小 * * *
4. Related to execution of system commands
Os.system (' command ') #运行shell命令, direct display. Equivalent to Python's exec ()
Os.popen (' command '). Read () #运行shell命令, which returns the execution result. Equivalent to Python's eval () * * *
Os.environ #系统的环境变量
5. Correlation with operating system differences
OS.SEP # Output operating system-specific path delimiter, win under "\ \", Linux for "/"
os.linesep # Output the line terminator used by the current platform, win under "\ r \ n", Linux "\ n"
os.pathsep # output string used to split the path of the file win under;, Linux for:
The os.name # Output string indicates the current use of the platform. Win-> ' NT '; Linux-> ' POSIX '
I. SYS module: an interface for interacting with the Python interpreter
SYS.ARGV command line argument list, the first element is the path of the program itself
Sys.exit (n) exit program, Exit normally on exit (0), error exit Sys.exit (1)
Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing
Sys.platform returns the operating system platform name
Python's modules