Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




The sys Module

The sys module provides access to some objects used or maintained by the interpreter and to functions that interact strongly with the interpreter.

The sys module also provides the three standard files used by Python.


Standard input file object; used by raw_input and input. Also available via and related methods of the file object.


Standard output file object; used by the print statement. Also available via sys.stdout.write() and related methods of the file object.


Standard error object; used for error messages, typically unhandled exceptions. Available via sys.stderr.write() and related methods of the file object.

A program can assign another file object to one of these global variables. When you change the file for these globals, this will redirect all of the interpreter's I/O.

One important object made available by this module is the variable sys.argv. This variable has the command line arguments used to run this script. For example, if we had a python script called, and executed it with the following command:

python -xvb display.csv

Then the sys.argv list would be ["", "-xvb", "display.csv"]. Sophisticated argument processing is done with the getopt or optparse modules.

A few other interesting objects in the sys module are the following variables.


The version of this interpreter as a string. For example, '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'


Version information as a tuple, for example: (2, 5, 1, 'final', 0).


Version information encoded as a single integer. Evaluating hex(sys.hexversion) yields '0x20501f0'.


Copyright notice pertaining to this interpreter.


Platform identifier, for example, 'darwin', 'win32' or 'linux2'.


Prefix used to find the Python library, for example '/usr', '/Library/Frameworks/Python.framework/Versions/2.5', 'c:\\Python25'.

  Published under the terms of the Open Publication License Design by Interspire