You are on page 1of 4

PART II

System Programming
This lirst in-uepth part ol the Look presents Python`s system programming tools÷
interlaces to services in the unuerlying operating system as well as the context ol an
executing program. It consists ol the lollowing chapters:
Chaptcr 2
This chapter proviues a comprehensive lirst look at commonly useu system inter-
lace tools. It starts slowly anu is meant in part as a relerence lor tools anu technigues
we`ll Le using later in the Look.
Chaptcr 3
This chapter continues the tour Legun in Chapter 2, Ly showing how Python`s
system interlaces are applieu to process stanuaru streams, commanu-line argu-
ments, shell variaLles, anu more.
Chaptcr -
This chapter continues our survey ol system interlaces Ly locusing on tools anu
technigues useu to process liles anu uirectories in Python. Ve`ll learn aLout Linary
liles, tree walkers, anu so on.
Chaptcr 5
This chapter is an introuuction to Python`s liLrary support lor running programs
in parallel. Here, you`ll linu coverage ol threaus, process lorks, pipes, sockets,
signals, gueues, anu the like.
Chaptcr ó
This last chapter is a collection ol typical system programming examples that uraw
upon the material ol the prior lour chapters. Python scripts here perlorm real tasks;
among other things, they split anu join liles, compare anu copy uirectory trees, test
other programs, anu search anu launch liles.
Although this part ol the Look emphasizes systems programming tasks, the tools
introuuceu are general-purpose anu are useu olten in later chapters.
www.it-ebooks.info
www.it-ebooks.info
CHAPTER 2
System Tools
“The os.path to Knowledge”
This chapter Legins our in-uepth look at ways to apply Python to real programming
tasks. In this anu the lollowing chapters, you`ll see how to use Python to write system
tools, GUIs, uataLase applications, Internet scripts, weLsites, anu more. Along the way,
we`ll also stuuy larger Python programming concepts in action: coue reuse, maintain-
aLility, oLject-orienteu programming (OOP), anu so on.
In this lirst part ol the Look, we Legin our Python programming tour Ly exploring
the systcns app|ication donain÷scripts that ueal with liles, programs, anu the general
environment surrounuing a program. Although the examples in this uomain locus on
particular kinus ol tasks, the technigues they employ will prove to Le uselul in later
parts ol the Look as well. In other worus, you shoulu Legin your journey here, unless
you are alreauy a Python systems programming wizaru.
Why Python Here?
Python`s system interlaces span application uomains, Lut lor the next live chapters,
most ol our examples lall into the category ol systcn too|s÷programs sometimes calleu
commanu-line utilities, shell scripts, system auministration, systems programming,
anu other permutations ol such worus. Regaruless ol their title, you are proLaLly al-
reauy lamiliar with this sort ol script; these scripts accomplish such tasks as processing
liles in a uirectory, launching test programs, anu so on. Such programs historically have
Leen written in nonportaLle anu syntactically oLscure shell languages such as DOS
Latch liles, csh, anu awk.
Even in this relatively simple uomain, though, some ol Python`s Letter attriLutes shine
Lrightly. For instance, Python`s ease ol use anu extensive Luilt-in liLrary make it simple
(anu even lun) to use auvanceu system tools such as threaus, signals, lorks, sockets,
anu their kin; such tools are much less accessiLle unuer the oLscure syntax ol shell
languages anu the slow uevelopment cycles ol compileu languages. Python`s support
lor concepts like coue clarity anu OOP also help us write shell tools that can Le reau,
73
www.it-ebooks.info
maintaineu, anu reuseu. Vhen using Python, there is no neeu to start every new script
lrom scratch.
Moreover, we`ll linu that Python not only incluues all the interlaces we neeu in oruer
to write system tools, Lut it also losters script portabi|ity. By employing Python`s stanu-
aru liLrary, most system scripts written in Python are automatically portaLle to all major
platlorms. For instance, you can usually run in Linux a Python uirectory-processing
script written in Vinuows without changing its source coue at all÷simply copy over
the source coue. Though writing scripts that achieve such portaLility utopia reguires
some extra ellort anu practice, il useu well, Python coulu Le the only system scripting
tool you neeu to use.
The Next Five Chapters
To make this part ol the Look easier to stuuy, I have Lroken it uown into live chapters:
º In this chapter, I`ll introuuce the main system-relateu mouules in overview lashion.
Ve`ll meet some ol the most commonly useu system tools here lor the lirst time.
º In Chapter 3, we continue exploring the Lasic system interlaces Ly stuuying their
role in core system programming concepts: streams, commanu-line arguments,
environment variaLles, anu so on.
º Chapter + locuses on the tools Python proviues lor processing liles, uirectories,
anu uirectory trees.
º In Chapter 5, we`ll move on to cover Python`s stanuaru tools lor parallel
processing÷processes, threaus, gueues, pipes, signals, anu more.
º Chapter 6 wraps up Ly presenting a collection ol complete system-orienteu pro-
grams. The examples here are larger anu more realistic, anu they use the tools
introuuceu in the prior lour chapters to perlorm real, practical tasks. This collection
incluues Loth general system scripts, as well as scripts lor processing uirectories ol
liles.
Especially in the examples chapter at the enu ol this part, we will Le concerneu as much
with system interlaces as with general Python uevelopment concepts. Ve`ll see non-
oLject-orienteu anu oLject-orienteu versions ol some examples along the way, lor in-
stance, to help illustrate the Lenelits ol thinking in more strategic ways.
“Batteries Included”
This chapter, anu those that lollow, ueal with Loth the Python language anu its standard
|ibrary÷a collection ol precoueu mouules written in Python anu C that are automat-
ically installeu with the Python interpreter. Although Python itsell proviues an easy-to-
use scripting language, much ol the real action in Python uevelopment involves this
vast liLrary ol programming tools (a lew hunureu mouules at last count) that ship with
the Python package.
74 | Chapter 2: System Tools
www.it-ebooks.info