OS Module
1 os.getcwd () Gets the current working directory, which is the directory path of the current Python script work 2 os.chdir ("DirName") changes the current script working directory, equivalent to the shell under CD 3 Os.curdir returns the current directory: ('. ') 4 OS.P Ardir Gets the parent directory string name of the current directory: (' ... ') 5 os.makedirs ('. ') can generate a multi-level recursive directory 6 os.removedirs (' dirname1 ') if the directory is empty, then delete, and recursively to The first level of the directory, if also empty, then delete, and so on 7 os.mkdir (' dirname ') to generate a single-level directory, equivalent to the shell mkdir dirname 8 os.rmdir (' dirname ') delete a single-level empty directory, if the directory is not empty can not be deleted, reported The equivalent of the shell rmdir dirname 9 os.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 ("O Ldname "," newname ") Rename File/directory Os.stat (' path/filename ') get File/directory information OS.SEP output operating system-specific path delimiter, win under" \ \ ", Linux under"/"OS.L INESEP output The line terminator used by the current platform, win under "\t\n", Linux under "\ n" os.pathsep output the string that is used to split the file path the Os.name output string indicates the current usage platform. Win-> ' NT '; Linux-> ' POSIX ' Os.system ("Bash command") runs a shell command that directly displays the Os.environ acquisition system environment variable Os.path.abspath (PATH) Returns path normalized absolute path Os.path.split (path) divides path into directory and file name two tuples return Os.path.dirname (path) to the directory where path is returned. In fact, the first element of Os.path.split (path), Os.path.basename, returns the last file name of path.If path ends with a/or \, then a null value is returned. The second element of Os.path.split (path) os.path.exists (path) returns true if path exists, or False24 os.path.isabs (path) If path does not exist If path is an absolute path, return True25 os.path.isfile (path) If path is an existing file, return true. Otherwise, return False26 Os.path.isdir (path) True if path is a directory that exists. Otherwise return False27 Os.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 last access time of the file or directory to which path is pointing os.path.getmtime (path) Returns the last modified time of the file or directory to which path is pointing
SYS module
1 sys.argv command line argument list, the first element is the program itself path 2 sys.exit (n) exit the program, exit gracefully (0) 3 sys.version get version information for Python interpreter 4 Sys.path Returns the search path of the module, initializes with the value of the PYTHONPATH environment variable 5 sys.platform returns the operating system platform name 6 Sys.stdout.write (' please: ')
Regular RE Module
1 '. ' The default match is any character except \ n, if you specify flag Dotall, match any character, including the line 2 ' ^ ' match character beginning, if you specify flags MULTILINE, this can also match (r "^a", "\nabc\neee", flags =re. MULTILINE) 3 ' $ ' matches the end of the character, or E.search ("foo$", "BFOO\NSDFSF", Flags=re. MULTILINE). Group () can also 4 ' * ' matches the character before the * number 0 or more times, Re.findall ("ab*", "Cabb3abcbbac") results for [' ABB ', ' ab ', ' a '] 5 ' + ' Match previous character 1 or more times, Re.findall ("ab+", "Ab+cd+abb+bba") result [' AB ', ' ABB '] 6 '? ' Match the previous character 1 or 0 times 7 ' {m} ' matches the previous character m times 8 ' {n,m} ' matches the previous character N to M times, Re.findall ("ab{1,3}", "ABB ABC abbcbbb") Results ' ABB ', ' AB ', ' ABB '] 9 ' | ' Match | left or | Right character, re.search ("abc| ABC "," ABCBABCCD "). Group () Results ' ABC ' 10 ' (...) ' Grouping matches, Re.search (" (ABC) {2}a (123|456) C "," abcabca456c "). Group () results Abcabca456c11 ' \a ' only matches from the beginning of the character, Re.search ("\aabc", "ALEXABC") is not matched to the end of the ' \z ' match character, with the $ ' \d ' Match number 0-916 ' \d ' matches non-digit ' \w ' match [a-za-z0-9]18 ' \w ' matches non-[a-za-z0-9]19 ' s ' matching whitespace characters, \ t, \ n, \ r, Re.search ("\s+", "Ab\tc1\n3"). Group () result ' \ t '
R represents the meaning of canceling special characters inside quotes
The most common matching syntax:
Re.match match from the beginning
Re.search Match contains
Re.findall all matching characters to the elements in the list to return
Re.splitall as a list of matched characters
Modules in Python