The os System Module
The os
module is the primary operating system (OS)
services interface. It provides generic operating-system 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
, that 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 but not Windows). Because the portability of such
calls changes over time, consult the Python Library Reference for
platform details.
Administrative Tools
Following are some miscellaneous module-related exports:
error
Known as both
os.error
and built-inOSError
exception. Raised foros
module-related errors. The accompanying value is a pair containing the numeric error code fromerrno
and the corresponding string, as would be printed by the C functionperror
( ). See the moduleerrno
in the Python Library Reference for names of the error codes defined by the underlying OS.When exceptions are classes, this exception carries two attributes:
errno
, the value of the Cerrno
variable; andstrerror
, the corresponding error message fromstrerror
( ). For exceptions that involve a file pathname (e.g.,chdir
( ),unlink
( )), the exception instance also contains the attributefilename
, the filename passed in. ...
Get Python Pocket Reference, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.