sys

sys has a double bushel of methods and attributes but only a few of interest to we beginning and intermediate users. The big ones it provides are the standard input and standard output routines ( standin and standout) but even those are not generally accessed directly. Actually, sys.exit() is about the only “practical” method in the whole module. Believe it or not, sys.stdin does not have a way to retrieve one typed letter at a time for specialized input routines.

sys.exit([arg])
Exit from Python. Unless you are a fairly advanced programmer you can ignore the optional “arg”.

sys.executable
A string giving the absolute path of the executable binary for the Python interpreter.

sys.getwindowsversion()
Returns a tuple describing the active Windows version. The tuple contains these elements:
major, minor, build, platform, service_pack, service_pack_minor, service_pack_major, suite_mask, product_type, all of which can be accessed by name and the first five of which by iteration. Platform has these values:
0 (VER_PLATFORM_WIN32s) Win32s on Windows 3.1
1 (VER_PLATFORM_WIN32_WINDOWS) Windows 95/98/ME
2 (VER_PLATFORM_WIN32_NT) Windows NT/2000/XP/x64
3 (VER_PLATFORM_WIN32_CE) Windows CE
For example, on a current Windows 10 computer as of March 2017:

wintup = sys.getwindowsversion()
print(wintup)
for i in range(0,len(wintup)-1):
    print(wintup[i])

…..yeilds….
sys.getwindowsversion(major=10, minor=0, build=14393, platform=2, service_pack=”)
10
0
14393
2
sys.modules
This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. Replacing or changing the dictionary will probably cause your program to crash.For example:

wintup = sys.getwindowsversion()
print(wintup)
for i in range(0,len(wintup)-1):
    print(wintup[i])

…..this is a small sample of the 192 entries yeilded from the dictionalry – note some are ‘(built-in)’ and some have paths….
tempfile : <module ‘tempfile’ from ‘D:\\Program Files (x86)\\Python\\lib\\tempfile.py’>
_signal : <module ‘_signal’ (built-in)>
codeop : <module ‘codeop’ from ‘D:\\Program Files (x86)\\Python\\lib\\codeop.py’>
dis : <module ‘dis’ from ‘D:\\Program Files (x86)\\Python\\lib\\dis.py’>
winreg : <module ‘winreg’ (built-in)>
tkinter.dialog : <module ‘tkinter.dialog’ from ‘D:\\Program Files (x86)\\Python\\lib\\tkinter\\dialog.py’>
lzma : <module ‘lzma’ from ‘D:\\Program Files (x86)\\Python\\lib\\lzma.py’>

sys.stdin – used by the input() command
sys.stdout – used by print() and the input() prompt
sys.stderr
File objects used by the interpreter for standard input, output and errors:

sys.version
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. For example: ”3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]”