The best way to get a feel for any book is to read it, of course. But especially for people who are familiar with the prior edition, this section will clarify regarding what is new this time around.
All of the example code has been upgraded to use the latest
features of the Python language and its standard library. Python is
still largely compatible with the code in the first two editions, but
recent language additions such as nested scopes and list
comprehensions simplify many coding tasks. For instance, default
arguments are no longer required to pass objects into most lambda
expressions, and the new email
package greatly simplifies the tasks of parsing and adding email
attachments. See the Python changes list earlier in this chapter for
more on this subject.
Although the GUI examples in this book required almost no code changes, they have been updated to run on Tk 8.4, the library used by Python 2.4 as its standard portable GUI toolkit. Among other things, the latest Tk allows window icons to be set by the program. Although begun under 2.4, this edition is also compatible with the upcoming Python 2.5 release.
A few chapters have been moved to make the flow more logical; for example, the sections on files and directories and the PyMailGUI example are now in chapters of their own. In addition, all appendixes were cut (this book is neither a reference nor a Python changes log), and a new initial preview chapter was added to introduce topics explored throughout the book.
As mentioned earlier, in deference to space, one second-edition chapter—that on the PyErrata web site—has been cut in this edition. Its main, unique topics on state retention have been incorporated into other chapters. The original source code for the PyErrata site still appears on the book’s examples package, as supplemental reading.[*]
You’ll find much-expanded coverage of Zope, the ZODB database,
threading tools and techniques including the queue
module, SQL interfaces, XML parsing,
and more. See the example and topic changes lists provided earlier for
additional details. Most of the new or expanded topics are a result of
the evolution of common practice in the Python world. While this book
doesn’t address core language evolution directly (the basics of new
language tools such as list comprehensions are the domain of the text
Learning Python), it does employ it throughout
its examples.
Except for some C integration examples, the majority of the programs in this edition were developed on Windows XP computers, with an eye toward portability to Linux and other platforms. In fact, some of the examples were born of my desire to provide portable Python equivalents of tools missing on Windows (e.g., file splitters). When programs are shown in action, it’s usually on Windows; they are demonstrated on the Linux platform only if they exercise Unix-specific interfaces.
This is not meant as a political statement; it is mostly a function of the fact that I wrote this book with Microsoft Word. When time is tight, it’s more convenient to run scripts on the same platform as your publishing tools than to frequently switch platforms. Luckily, because Python has become so portable, the underlying operating system is largely irrelevant to developers. Python, its libraries, and its Tkinter GUI framework work extremely well on all major platforms today.
Where platform issues do come into play, though, I’ve made the examples as platform-neutral as possible, and I point out platform-specific issues along the way. Generally speaking, most of the scripts should work unchanged on common Python platforms. For instance, all the GUI examples were tested on both Windows (ME, XP) and Linux (KDE, Gnome), and most of the command-line and thread examples were developed on Windows but work on Linux too. Because Python’s system interfaces are built to be portable, this is easier than it may sound; it’s largely automatic.
On the other hand, this book does delve into platform-specific topics where appropriate. For instance, there is coverage of many Windows-specific topics—Active Scripting, COM, program launch options, and so on. Linux and Unix readers will also find material geared toward their platforms—forks, pipes, and the like.
The one place where readers may still catch a glimpse of platform biases is in the Python/C integration examples. For simplicity, the C compilation details covered in this text are still somewhat Unix/Linux-oriented. One can make a reasonable case for such a focus—not only does Linux come with C compilers, but the Unix development environment it provides grew up around that language. On standard Windows, the C code shown in this book will work, but you may need to use different build procedures (they vary per Windows compiler, some of which are very similar to Linux compilers).
In fact, for this third edition of the book, many of the C integration examples were run on the Cygwin system, not on Linux. Cygwin provides a complete, Unix-like environment and library for Windows. It includes C development tools, command-line utilities, and a version of Python that supports Unix tools not present in the standard Windows Python, including process forks and fifos. Unlike Linux, because it runs on Windows, Cygwin does not require a complete operating system installation (see http://www.cygwin.com).
Cygwin has a GPL-style, open source license that requires giving away code (more on this later in the book). If you do not wish to download and install Cygwin, you may have to translate some of the C integration build files for your platform; the standard C development concepts apply. On standard Windows, you’ll have to translate for your C compiler. O’Reilly has published an outstanding text, Python Programming on Win32, that covers Windows-specific Python topics like this, and it should help address any disparity you may find here.
Becoming proficient in Python involves two distinct tasks: learning the core language itself, and then learning how to apply it in applications. This book addresses the latter (and larger) of these tasks by presenting Python libraries, tools, and programming techniques.
Learning Python syntax and datatypes is an important first step, and a prerequisite to this book. Very soon after you’ve learned how to slice a list, though, you’ll find yourself wanting to do real things, like writing scripts to compare file directories, responding to user requests on the Internet, displaying images in a window, reading email, and so on. Most of the day-to-day action is in applying the language, not the language itself.
That’s what this book is for. It covers libraries and tools beyond the core language, which become paramount when you begin writing real applications. It also addresses larger software design issues such as reusability and OOP, which can be illustrated only in the context of realistically scaled programs. Because it assumes you already know Python, this is a somewhat advanced text; again, if you find yourself lost, you might do well to learn the core language from other resources before returning here.
Although this book teaches concepts before applying them, it still contains many larger working programs that tie together concepts presented earlier in the book and demonstrate how to use Python for realistically scaled tasks. Among them:
- PyEdit
A Python/Tk text-file editor object and program
- PyView
A photo image and note-file slideshow
- PyDraw
A paint program for drawing and moving image objects
- PyTree
A tree data structure drawing program
- PyClock
A Python/Tk analog and digital clock widget
- PyToe
An AI-powered graphical tic-tac-toe program
- PyForm
A persistent object table browser
- PyCalc
A calculator widget in Python/Tk
- PyMailGUI
A Python/Tkinter POP and SMTP email client
- PyFtp
A simple Python/Tk file-transfer GUI
- PyMailCGI
A web-based email client interface
- PyPhoto
A new thumbnail picture viewer with resizing and saves
See the earlier example changes list for more about how some of
these have mutated in this edition. Besides the major examples listed
here, there are also mixed-mode C integration examples (e.g., callback
registration and class object processing); SWIG examples (with and
without “shadow” classes for C++); more Internet examples (FTP upload
and download scripts, NNTP and HTTP examples, email tools, and
socket
and select
module examples); many examples of
Python threads and thread queues; and coverage of Jython, HTMLgen,
Zope, COM, XML parsing, and Python ZODB and MySQL database interfaces.
In addition, as mentioned earlier, the second edition’s PyErrata web
site example appears in the examples distribution.
[*] I regret cutting this chapter, but new material was added, and as you can tell, this is already a substantial book. As my first editor, Frank Willison, famously said when the second edition came out, if this book were run over by a truck, it would do damage....
Get Programming Python, 3rd 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.