Python's os module

Python's os module is used to interact with the operating system. Let's explore it a little bit.

The os module has many uses. We won’t be covering everything that it can do. Instead, we will get an overview of its uses and we’ll also take a look at one of its sub-modules, known as os.path. Specifically, we will be covering the following:

  • os.name
  • os.environ
  • os.chdir()
  • os.getcwd()
  • os.getenv()
  • os.putenv()
  • os.mkdir()
  • os.makedirs()
  • os.remove()
  • os.rename()
  • os.rmdir()
  • os.startfile()
  • os.walk()
  • os.path

That looks like a lot to cover, but there is at least ten times as many other actions that the os module can do. This chapter is just going to give you a little taste of what’s available. To use any of the methods mentioned in this section, you will need to import the os module, like this:

Get hands-on with 1200+ tech skills courses.