Description of common functions of the Python OS module, and functions of the pythonos Module
The OS module in the Python standard library contains common operating system functions. This module is especially important if you want your program to be unrelated to the platform. That is, it allows a program to run in Linux and Windows without any changes or any problems.
The following lists some useful parts in the OS module. Most of them are simple and clear.
OS. sepIt can replace the path separator specified by the operating system. \ In windows
OS. nameString indicates the platform you are using. For example, for Windows, it is 'nt ', and for Linux/Unix users, it is 'posix '.
OS. getcwd ()Function to get the current working directory, that is, the directory path of the current Python script.
OS. getenv ()Obtain an environment variable. If none is not returned
OS. putenv (key, value)Set an environment variable value
OS. listdir (path)Returns the names of all objects and directories in the specified directory.
OS. remove (path)The function is used to delete an object.
OS. system (command)Function is used to run shell commands.
OS. linesepString indicates the row Terminator used by the current platform. For example, in Windows, '\ r \ n' is used, in Linux,' \ n' is used, and in Mac, '\ R' is used '.
OS. path. split (p)The function returns the directory name and file name of a path.
OS. path. isfile ()AndOS. path. isdir ()Check whether the given path is a file or a directory.
OS. path. existe ()Function is used to check whether the given path actually exists.
OS. curdir:Returns the current directory ('.')
OS. chdir (dirname ):Change the working directory to dirname
OS. path. getsize (name ):Get the file size. If the name is a directory, return 0L
OS. path. abspath (name ):Obtain absolute path
OS. path. normpath (path ):Standard path string format
OS. path. splitext ():Separating file names and extensions
OS. path. join (path, name ):Connection directory and file name or directory
OS. path. basename (path ):Returned file name
OS. path. dirname (path ):Returned file path