Introductory Programming in Python: Lesson 21
Operating System Functionality

[Prev: Basic Parsing] [Course Outline] [Next: Handling Dates and Times]

An Overview of the os Module

The os module provides a large set of functions with which we can both query and manipulate the environment within which our program runs, and the file systems within which it operates. The functions are provided in the os module, which we can access by importing os.

Python 2.4.3 (#1, Oct	2 2006, 21:50:13) 
[GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>

Process Parameters and Environment

The following functions can be used to determine or change the environment (in a computer sense) in which our programs run.

Files and Directories

In addition there are a variety of functions which can be used to manipulate files and directories without opening them. These functions are powerful, and have effects outside of your program, and beyond its runtime. Use them with care, especially rename, remove, and rmdir.

Path String Management

The path manipulation functions in os.path are also very useful. os.path can be accessed as a sub-module of os, by importing os, or directly, by importing os.path, as in

>>> import os.path
>>>

Exercises

[Prev: Basic Parsing] [Course Outline] [Next: Handling Dates and Times]