Interacting with the OS
One of the most common uses of Python is to write code that interacts with the OS and its filesystem. Whether you are working with files or you just need some basic information about the OS, this topic will cover the essentials of how to do it in a multiplatform way through the os
, sys
, platform
, and pathlib
modules of the standard library.
OS Information
There are three key modules that are used to inspect the runtime environment and the OS. The os
module enables miscellaneous interfaces with the OS. You can use it to inspect environment variables or to get other user and process-related information. This, combined with the platform
module, which contains information about the interpreter and the machine where the process is running, and the sys
module, which provides you with helpful system-specific information, will usually provide you with all the information that you need about the runtime environment.