First, Introduction
The module is a file that holds the Python code. Modules can define functions, classes, and variables. The module can also contain executable code, the module is divided into three kinds:
- Custom Modules
- Built-in standard modules
- Open source module (third party)
Second, commonly used built-in modules
- OS Module
Role:
Used to provide system-level operations
Function:
OS.GETCWD () Gets the current working directory, which is the directory path of the current Python script work os.chdir ("dirname") To change the current script working directory, equivalent to the shell under Cdos.curdir return to the current directory: ('.') Os.pardir Gets the parent directory string name of the current directory: ('..') Os.makedirs ('Dir1/dir2') to generate a multi-level recursive directory Os.removedirs ('dirname1'If the directory is empty, it is deleted and recursively to the previous level of the directory, if it is also empty, then delete, and so on OS.mkdir('dirname') to generate a single-level directory, equivalent to mkdir in the shelldirnameOS.rmdir('dirname'Delete the single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to rmdir in the shelldirnameOs.listdir ('dirname'lists all files and subdirectories under the specified directory, including hidden files, and prints a list of os.remove () deletes a file Os.rename ("oldname","New") Rename File/directory OS.Stat('Path/filename') Get File/directory information OS.SEP operating system-specific path delimiter, win under"\\", under Linux for"/"Os.linesep The line terminator used by the current platform, win under"\t\n", under Linux for"\ n"os.pathsep The string Os.name string used to split the file path indicates the current usage platform. Win-'NT'; Linux->'POSIX'Os.system ("Bash Command"run the shell command to directly display the Os.environ get system environment variable Os.path.abspath (PATH) returns path normalized absolute path Os.path.Split(path) splits path into directory and file name two tuples return Os.path.dirname(path) Returns the directory of path. is actually os.path.Splitthe first element of the (path) Os.path.basename(path) Returns the last file name of path. If path ends with a/or \, then a null value is returned. That is Os.path.Splitthe second element of path, os.path.exists (path), returns True if path exists, or if path does not exist, returns Falseos.path.isabs (path) If path is an absolute path and returns TRU Eos.path.isfile (path) returns True if path is a file that exists. Otherwise, return Falseos.path.isdir (path) True if path is a directory that exists. Otherwise, return Falseos.path.Join(path1[, path2[, ...]) When multiple paths are combined and returned, the parameters before the first absolute path are ignored Os.path.getatime (path) returns the file or directory to which path points to the last access time Os.path.getmtime (path) returns the file or directory that the path points to The last modified timeView Code
- SYS module
- Time Module
- DateTime module
- Pickle Module
- Random module
- Hashlib Module
Python Base Module