System Scripting Overview
The next two sections will take a quick tour through
sys
and os
, before this chapter
moves on to larger system programming concepts. 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 (e.g., glob
,
socket
, thread
,
time
, fcntl
), and some built-in
functions are really 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 search path), and os
contains variables
and functions that map to the operating system on which Python is
run. In practice, this distinction may not always seem clear-cut
(e.g., the standard input and output streams show up in
sys
, but they are at least arguably tied to
operating system paradigms). The good news is that you’ll soon
use the tools in these modules so often that their locations will be
permanently stamped on your memory.[9]
The os
module also attempts to provide a
portable programming interface to the underlying operating system ...
Get Programming Python, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.