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-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 error codes defined by the underlying OS.

When exceptions are classes, this exception carries two attributes: errno, the value of the C errno variable; and strerror, the corresponding error message from strerror( ). For exceptions that involve a file pathname (e.g., chdir( ), unlink( )), the exception instance also contains the attribute filename, 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.