os module

I also paste someone else's here, I haven't tried it yet, come and find it if you need it.

 

os module

Provides an interface for making calls to the operating system

1  os.getcwd() Get the current working directory, that is, the directory path where the current python script works
 2 os.chdir( " dirname " ) Change the working directory of the current script; equivalent to cd under the shell
 3 os.curdir returns the current directory: ( ' . ' )
 4 os.pardir Get the parent directory string name of the current directory: ( ' .. ' )
 5 os.makedirs( ' dirname1/dirname2 ' ) Can generate multiple recursive directories
 6 os.removedirs( ' dirname1 ' ) If the directory If it is empty, delete it, and recurse to the previous directory. If it is also empty, delete it, and so on.
 7 os.mkdir( ' dirname ' ) Generate a single-level directory; equivalent to mkdir dirname
 8 os.rmdir( in the shell' dirname ' ) delete a single-level empty directory, if the directory is not empty, it cannot be deleted, and an error is reported; equivalent to rmdir dirname
 9 os.listdir( ' dirname ' ) in the shell List all files and subdirectories in the specified directory, including hidden files , and prints it as
 a list10  os.remove() removes a
 file11 os.rename ( " oldname " , " newname " ) renames a file/ directory12
 os.stat ( ' path/filename ' ) gets file/ directory information13
 os.sep outputs the OS-specific path separator, " \\ " under win, " / " under Linux 14 os.linesep output the line terminator used by the current platform, "" under win
\r\n " , " \n "  
 under Linux 15  os.pathsep Output string used to split file paths
 16 os.name Output string indicates the current platform in use. win-> ' nt ' ; Linux-> ' posix ' 
17 os.system( " bash command " ) Run the shell command and display it directly
 18  os.environ Get system environment variables
 19  os.path.abspath(path) Return the absolute path normalized by path
 20  os.path.split(path) Will path is split into directory and file name two-tuple return
 21  os.path.dirname(path) returns the directory of path. In fact, it is the first element of
 os.path.split(path) 22  os.path.basename(path) returns The last file name of path. If path ends with / or \, then it will return a null value. That is, the second element of os.path.split(path)
 23 os.path.exists(path) Returns True if path exists; returns False if path does not exist
 24  os.path.isabs(path) Returns True if path is an absolute path
 25  os.path.isfile(path) if path is an existing file, returns True. Otherwise returns False
 26  os.path.isdir(path) Returns True if path is an existing directory. Otherwise return False
 27  os.path.join(path1[, path2[, ...]]) Return after combining multiple paths, parameters before the first absolute path will be ignored
 28  os.path.getatime(path) Returns the last access time of
 the file or directory pointed to by path 29 os.path.getmtime(path) Returns the last modification time of the file or directory pointed to by path

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324489791&siteId=291194637