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:
errorAn alias for the built-in
OSErrorexception. Raised forosmodule-related errors. The accompanying value is a pair containing the numeric error code fromerrnoand the corresponding string, as would be printed by the C functionperror(). See the moduleerrnoin the Python Library Reference for names of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access