Product SiteDocumentation Site

12.4. Module os

os module provides operating system dependent functionality. You can import it using the following import statement.

>>> import os

getuid() function returns the current process's effective user's id.

>>> os.getuid()

getpid() returns the current process's id. getppid() returns the parent process's id.

>>> os.getpid()
>>> os.getppid()

uname() returns different information identifying the operating system, in Linux it returns details you can get from the uname command. The returned object is a tuple, (sysname, nodename, release, version, machine)

>>> os.uname()
('Linux', 'd80', '', '#1 SMP Wed Sep 15 03:27:15 UTC 2010', 'i686')

getcwd()returns the current working directory. chdir(path) changes the current working directory to path. In the example we first see the current directory which is my home directory and change the current directory to /tmp and then again checking the current directory.
>>> os.getcwd()
>>> os.chdir('/tmp')
>>> os.getcwd()