[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

eventually changed so as to make this fix irrelevant for its own use case (see Chap-
ter 11), but other clients still acquire the fix for free.


Also notice how some of the classes in this example use the sys.executable path string
to obtain the Python executable’s full path name. This is partly due to their role in user-
friendly demo launchers. In prior versions that predated sys.executable, these classes
instead called two functions exported by a module named Launcher.py to find a suitable
Python executable, regardless of whether the user had added its directory to the system
PATH variable’s setting.


This search is no longer required. Since I’ll describe this module’s other roles in the
next chapter, and since this search has been largely precluded by Python’s perpetual
pandering to programmers’ professional proclivities, I’ll postpone any pointless peda-
gogical presentation here. (Period.)


Other System Tools Coverage


That concludes our tour of Python system tools. In this and the prior three chapters,
we’ve met most of the commonly used system tools in the Python library. Along the
way, we’ve also learned how to use them to do useful things such as start programs,
process directories, and so on. The next chapter wraps up this domain by using the
tools we’ve just met to implement scripts that do useful and more realistic system-level
work.


Still other system-related tools in Python appear later in this text. For instance:



  • Sockets, used to communicate with other programs and networks and introduced
    briefly here, show up again in Chapter 10 in a common GUI use case and are
    covered in full in Chapter 12.

  • Select calls, used to multiplex among tasks, are also introduced in Chapter 12 as a
    way to implement servers.

  • File locking with os.open, introduced in Chapter 4, is discussed again in conjunc-
    tion with later examples.

  • Regular expressions, string pattern matching used by many text processing tools
    in the system administration domain, don’t appear until Chapter 19.


Moreover, things like forks and threads are used extensively in the Internet scripting
chapters: see the discussion of threaded GUIs in Chapters 9 and 10; the server imple-
mentations in Chapter 12; the FTP client GUI in Chapter 13; and the PyMailGUI pro-
gram in Chapter 14. Along the way, we’ll also meet higher-level Python modules, such
as socketserver, which implement fork and thread-based socket server code for us. In
fact, many of the last four chapters’ tools will pop up constantly in later examples in
this book—about what one would expect of general-purpose portable libraries.


268 | Chapter 5: Parallel System Tools

Free download pdf