The OS modules in the Python standard library contain common operating system features. This module is especially important if you want your program to be platform-agnostic. That is, it allows a program to be written without any changes or problems, and can be run under Linux and Windows. Some of the more useful parts of the OS module are listed below. Most of them are simple and straightforward. OS.SEP can replace operating system-specific path separators. The Os.name string indicates the platform you are using. For example, for Windows, it's ' NT ', and for Linux/unix users, it's ' POSIX '. The OS.GETCWD () function gets the current working directory, which is the directory path of the current Python script work. The Os.getenv () and os.putenv () functions are used to read and set environment variables, respectively. Os.listdir () returns all file and directory names under the specified directory. The Os.remove () function is used to delete a file. The Os.system () function is used to run the shell command. The OS.LINESEP string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ', Linux uses ' \ n ' and Mac uses ' \ R '. The Os.path.split () function returns the directory name and file name of a path. The Os.path.isfile () and Os.path.isdir () functions respectively verify that the given path is a file or a directory. The Os.path.existe () function is used to verify that the given path really exists in the OS and Os.path module Os.listdir (dirname): Lists directories and files under DirName os.getcwd (): Get current working directory Os.curdir : Return but previous directory ('. ') Os.chdir (dirname): Change the working directory to dirname This article from: (www.91linux.com) Detailed source reference: http://www.91linux.com/html/article/program/ Python/20081127/13983.html
Python OS Common modules