O'Reilly logo

Python Pocket Reference, 4th Edition by Mark Lutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required