System Scripting Overview
We will take a quick tour through the standard library sys and os modules in the first few sections of this
chapter before moving on to larger system programming concepts. As you
can tell from the length of their attribute lists, both of these are
large modules (their content may vary slightly per Python version and
platform):
>>>import sys, os>>>len(dir(sys))# 56 attributes 56 >>>len(dir(os))# 118 on Windows, more on Unix 118 >>>len(dir(os.path))# a nested module within os 43
As I’m not going to demonstrate every item in every built-in module, the first thing I want to do is show you how to get more details on your own. Officially, this task also serves as an excuse for introducing a few core system scripting concepts; along the way, we’ll code a first script to format documentation.
Python System Modules
Most system-level interfaces in Python are shipped in
just two modules: sys and os. That’s somewhat oversimplified; other standard
modules belong to this domain too. Among them are the
following:
globFor filename expansion
socketFor network connections and Inter-Process Communication (IPC)
threadandqueueFor concurrent threads
timeFor accessing system time details
fcntlFor low-level file control
In addition, some built-in functions are actually system
interfaces as well (e.g., open).
But sys and os together form the core of Python’s
system tools arsenal.
In principle at least, sys
exports components related to the Python
interpreter itself (e.g., the module ...