I l@ve RuBoard |
![]() ![]() |
Major Changes in This EditionThe best way to get a feel for any book is to read it, of course. But especially for people who are familiar with the first edition, the next few sections go into more detail about what is new in this edition. It's Been Updated for Python 2.0This edition has been updated for Python 2.0, and the Graphical User Interface (GUI) material has been updated for Tk versions 8.0 or later. Technically, this update was begun under Python 1.5.2, but all examples were revisited for 2.0 before publication. For the trivia buffs among you: release 2.0 was the first Python release following Guido's move to BeOpen, while 1.6 was the last release from Guido's prior employer, CNRI. Just before I finished this book's final draft and after the 2.0 release, Guido and the core Python development team moved from BeOpen to Digital Creations, home of the Zope web application construction kit, but this move is independent of Python releases (see Chapter 1, for more details). Release 2.0 introduces a few language extensions, but 2.0 and 1.6 are similar in content, and the updates just add a handful of features. The examples in this book should generally work with later Python releases. Remarkably, almost all examples in the first edition still work five years later, with the latest Python releases; those that didn't work required only small fixes (e.g., GUI call formats and C API interfaces). On the other hand, although the core language hasn't changed much since the first edition, a number of new constructs have been added, and we'll apply them all here. Among these new Python features: module packages, class exceptions, pseudo-private class attributes, unicode strings, the new regular expression module, new Tkinter features such as the grid manager, standard dialogs, and top-level menus, and so on. A new appendix summarizes all of the major changes in Python between the first and second editions of this book. In addition to the language changes, this book presents new Python tools and applications that have emerged in recent years. Among them: the IDLE programming interface, the JPython (a.k.a. "Jython") compiler, Active Scripting and COM extensions, the Zope web framework, Python Server Pages (PSP), restricted execution mode, the HTMLgen and SWIG code generators, thread support, CGI and Internet protocol modules, and more (it's been a busy five years). Such applications are the heart and soul of this second edition. It's Been Refocused for a More Advanced AudienceThis edition presents Python programming by advanced examples. Becoming proficient in Python involves two distinct tasks: learning the core language itself, and then learning how to apply it in applications. This edition addresses the latter (and larger) of these tasks by presenting Python libraries, tools, and programming techniques. Since this is a very different focus, I should say a few words about its rationale here. Because there were no other Python books on the horizon at the time, the first edition was written to appeal to many audiences at once -- beginners and gurus alike. Since then, another O'Reilly book, Learning Python, has been developed to address the needs of beginners, and Python Pocket Reference was published for readers seeking a short Python reference. As a result, the core language introductory-level material and the original reference appendixes have been removed from this book. Learning Python introduces the core language -- its syntax, datatypes, and so on -- using intentionally simplistic examples. Many have found it to be ideal for learning the language itself, but Python can become even more interesting once you master the basic syntax and can write simple examples at the interactive prompt. Very soon after you've learned how to slice a list, you 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. Programming Python focuses on the "everything else" of Python development. 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 only be illustrated in the context of realistically scaled programs. In other words, Programming Python, especially in this new edition, is designed to pick up where Learning Python leaves off. Therefore, if you find this book too advanced, I encourage you to read Learning Python as a prelude to this text, and return here for the rest of the story once you've mastered the basics. Unless you already have substantial programming experience, this edition might serve you best as a second Python text. It Covers New TopicsMost of the changes in this edition were made to accommodate new topics. There are new chapters and sections on Internet scripting, CGI scripts, operating system interfaces, the SWIG integration code generator, advanced Tkinter topics, the HTMLgen web page generator, JPython, threads, restricted execution mode, and more. You should consult the Table of Contents for the full scoop, but here are some of the new topics and structural changes you'll find in this edition:
Although later chapters build upon material in earlier chapters, topics in this edition are covered fairly independently, and are associated by book parts. Because of that, it's not too much of a stretch to consider this edition to be akin to four or five books in one. Its top-level structure underscores its application topics focus:
Two notes here: First of all, don't let these titles fool you -- although most have to do with application topics, Python language features and general design concepts are still explored along the way, in the context of real-world goals. Second, readers who use Python as a standalone tool can safely skip the integration chapters, though I still recommend a quick glance. C programming isn't nearly as fun or easy as Python programming. Yet because integration is central to Python's role as a scripting tool, a cursory understanding can be useful, regardless of whether you do integrating, scripting, or both. First edition readers will notice that most of this material is new, and even chapters with old titles contain largely new material. Noticeably absent in this edition are the original Sneak Preview, Mini Reference, Tutorial Appendix, and all of the old Part II -- a reflection of the new focus and intended readership. It's More Example-OrientedThis book is largely about its examples. In this edition, old examples have been extended to become more realistic (e.g., PyForm and PyCalc), and new examples have been added throughout. Among the major examples, you'll find:
There are also new 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 new socket and select module examples), many new examples of Python threads, and new coverage of JPython, HTMLgen, Zope, Active Scripting, COM, and Python database interfaces. Many of the new examples are somewhat advanced, but of course this is now a somewhat advanced text. In addition, the old Python/C embedding API (now called ppembed ) has been extended to support precompiling strings to bytecode, and the original calculator example (now called PyCalc) has been beefed up to support keyboard entry, history lists, colors, and more. In fact, the new book examples tree distributed on this edition's CD-ROM (see http://examples.oreilly.com/python2) is itself a fairly sophisticated Python software system, and the examples within it have been upgraded structurally in a number of important ways:
It's More Platform-NeutralExcept for some C integration examples, the majority of the programs in this edition were developed on my Windows 98 laptop, 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 Red Hat Linux 6.x platform only if they exercise Unix-specific interfaces. This is not a political statement at all -- I like Linux too. It's mostly a function of the fact that I wrote this book with MS Word; when time is tight, it's more convenient to run scripts on the same platform as your publishing tools than to frequently reboot into Linux. Luckily, because Python has now become so portable to both Windows and Linux, the underlying operating system is less of a concern to Python developers than it once was. Python, its libraries, and its Tkinter GUI framework all work extremely well on both platforms today. Because I'm not a politician, though, I've tried to make the examples as platform-neutral as possible, and point out platform-specific issues along the way. Generally speaking, most of the scripts should work on common Python platforms unchanged. For instance, all the GUI examples were tested on both Windows (98, 95) 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 generally built to be portable, this is easier than it may sound. On the other hand, this book does delve into platform-specific topics where appropriate. There is new coverage of many Windows-specific topics -- Active Scripting, COM, program launch options, and so on. Linux and Unix readers will also find material geared towards their platforms -- forks, pipes, and the like. There is also new discussion of ways to edit and run Python programs on most major platforms. 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-biased. One can at least make a reasonable case for such a focus -- not only does Linux come with C compilers for free, but its development environment grew up around that language. On Windows, the C extension code shown in this book will work, but you may need to use different build procedures that vary per Windows compiler. O'Reilly has published an outstanding text, Python Programming on Win32, that covers Windows-specific Python topics like this, and should help address some of the disparity here. If you do Windows-specific programming, please see that book for all Windows details skipped here.
![]() |
I l@ve RuBoard |
![]() ![]() |