The os System Module

The os module is the primary operating system (OS) services interface. It provides generic OS support and a standard, platform-independent OS interface. The os module includes tools for environments, processes, files, shell commands, and much more. It also includes a nested submodule, os.path, which provides a portable interface to directory processing tools.

Scripts that use os and os.path for systems programming are generally portable across most Python platforms. However, some os exports are not available on all platforms (e.g., fork is available on Unix and Cygwin, but not in the standard Windows version of Python). Because the portability of such calls can change over time, consult the Python Library Reference for platform details.

See also related system modules: glob (filename expansion); tempfile (temporary files); signal (signal handling); socket (networking and IPC); threading (multithreading); queue (thread communication); subprocess (spawned command control); multiprocessing (threading-like API for processes); getopt and optparse (command-line processing); and others.

Administrative Tools

Following are some miscellaneous module-related exports:

error

An alias for the built-in OSError exception. Raised for os module-related errors. The accompanying value is a pair containing the numeric error code from errno and the corresponding string, as would be printed by the C function perror(). See the module errno in the Python Library Reference for names of the ...

Get Python Pocket Reference, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.