CHARMING PYTHON #12 (20000095) Book Roundup David Mertz, Ph.D. Machinist, Gnosis Software, Inc. January, 2001 In a bit more than a year the Python community has gone from having a thin selection of books to recommend to the current forest of dead trees available to help with learning and programming in Python. Some books are general introductions to the Python language, while others specialize in particular tasks. Even within the general books, level and focus differs considerably. This column gives the David's impressions and recommendations on eight of the best known books about Python. WHAT IS PYTHON? ------------------------------------------------------------------------ Python is a freely available, very-high-level, interpreted language developed by Guido van Rossum. It combines a clear syntax with powerful (but optional) object-oriented semantics. Python is available for almost every computer platform you might find yourself working on, and has strong portability between platforms. INTRODUCTION ------------------------------------------------------------------------ This column should provide readers with a good guide to most of the books on Python currently available for purchase. As of this writing, I know of a few books that are available--or are expected to be available soon--that I have simply not had the opportunity to look at. By the time you read this, more may have been announced and/or published. It is an exciting time to be a Python programmer; in some part because computer book publishers are catching on to how "hot" Python is as a programming language. I apologize to any author or publisher that has slipped completely by my notice, but I will mention the following titles that are not reviewed here, but that readers might still want to investigate on their own: * _Core Python Programming_, Wesley J. Chun, Prentice Hall (December 2000). * _Python Annotated Archives_, Martin C. Brown, McGraw-Hill (December 1999). * _Programming with Python_, Tim Altom, Prima Publishing (October 1999). * _Sams Teach Yourself Python in 24 Hours_, Ivan Van Laningham, Sams (May 2000). * _Python: Developer's Handbook_, Andre dos Santos Lessa, Sams (December 2000). * _Learn to Program Using Python_, Alan Gauld, Addison-Wesley (January 2001). * _Internet Programming with Python_, Aaron Watters, et alia, Hungry Minds (September 1996). Out of print. While books are a wonderful way to get started with most topics (including Python), there is also very good documentation that accompanies Python itself. Take a look at: http://python.org/doc/ to get yourself started. The Python team have written a quite excellent introductory tutorial, and the quality of the the module index, library reference, language reference are much better than most programming languages, or free software in general, has (but the distinction between the latter two items is always fuzzy to me when I go to look something up... try both if in doubt). One "book" that is not discussed in this column is an unfortunate ommission. _The Standard Python Library_ is written by Fredrik Lundh, who is truly one of the great resources of the Python community (called the "eff-bot" after his machinic rigor and his signature "/F"). General sentiment is that this is a well-written book; but it is only available in "encrypted" electronic form. Many attempted users have complained of many annoyance with the book breaking and/or disabling itself when computer hardware/software changes; and in the best of cases, the eff-bot book is currently Win32-only. Your humble author has had similar problems with other Glassbook-format titles. Overall, this electronic distribution approach is just simply not one I can endorse; so I simply passed on attempting to dig up a Win32 machine to devote to restricted reading of this text. Mind you, I have nothing generally against electronic texts (my column as you are probably reading it is an electronic text). But "copy protection" obscurantism is a strong-arm tactic which is politically contemptible, grants far less "rights" than do printed books, and is fragile waste of users time. The good news is that this same text is due to be published in dead-tree form this coming year. PYTHON REFERENCES FOR EXPERIENCED PROGRAMMERS ------------------------------------------------------------------------ Programmers who already know Python--or perhaps who do not know Python, but know other programming language with similar capabilities--will be best served picking up a reference book to provide them with gentle reminders of syntax, modules, and available functions. For books of this sort, one rarely wants to read cover-to-cover, but a good quality index is essential. Information should be grouped logically and compactly. The _Python Pocket Reference_ is a thin 75 page, small-format book. More than anything, _Python Pocket Reference_ resembles a set of 3x5 index cards one might keep to jog your memory on a topic (the actual size is slightly larger, but not that much). Basically, _Python Pocket Reference_ has lists of everything that can helpfully be listed about Python: command-line arguments; environment variables; operators; keywords; syntax rules for statements; builtin functions; magic methods; and the capabilities of the most important standard modules (and a few other things). It is easy to scan through an appropriate list, once you have a general idea about the type of thing you are looking for. Missing from _Python Pocket Reference_ is any index or cross-references. The book is short enough that it is not too hard to skim a relevant section, but an explicit index would be an improvement (an extra five pages at the end would not push it past "pocket sized"). Examples are also rare in _Python Pocket Reference_; a function's arguments might be listed, for example, but an example or two would be a useful addition in many cases. Overall, I find _Python Pocket Reference_ just a bit too thin and summary to be of huge use, especially since I generally have the library reference and language reference a few keystrokes away at those times I need the sort of answer _Python Pocket Reference_ will provide. More to my own taste is the excellent _Python Essential Reference_. At 320 pages and with an academic-paperback form factor, _Python Essential Reference_ is a lot easier to carry around than any of the other Python books reviewed below. But do not expect to fit it in any pockets (maybe an outside pocket of a winter-jacket). As well, the book is set in an 8 or 9-point typeface (a clean serif face with nice use of fixed, sans serif, and demibold contrasts for examples, lists, and so on). This makes for a lot more words packed into a reasonable size, but also is likely to make for some squinting and leaning over for those programmers with less-than-perfect vision. _Python Essential Reference_ is simply excellent in both writing clarity and editorial aids. The index is extremely professional, and points you competently to relevant sections (it neither underindexes nor overindexes, both of which are pitfalls for computer topics). I might quibble with the typographic choice of serif-bold for the index main items, which feels too heavy, but that is a trifle. In addition, many sections contain inline "See also" notes that list page numbers and section titles. This brings the power of hypertext to the convenience of a bound volume. The general topics covered by _Python Essential Reference_ are similar to those in _Python Pocket Reference_, but with more detail of coverage, and with more coverage of extension modules. As well, most formal description is accompanied by well chosen examples of a function/module/construct in action. The remarkable thing Beazley has accomplished is to organize related concepts in such a way that you can get a quick sense of a given function by reading its subsection, but reading a whole section or chapter nonetheless has a natural flow to it. _Python Essential Reference_ has some brief introductory material to Python as a language, which might suffice for a programmer with experience in several other languages, but for someone really getting started, one of the below texts is a better choice for a first book (but get Beazley's anyway, to refer to later). GENTLE INTRODUCTIONS TO THE PYTHON LANGUAGE ------------------------------------------------------------------------ The godfather of Python books is Mark Lutz' _Programming Python_. I am not certain whether it was the first book published on Python, but for several years it was the standard one to refer users to. _Programming Python_ is fairly ambitious as a project. It is one of those 900 page computer references one finds in stores, but without the fluff and filler of many such tomes. Lutz's general approach is to introduce readers to Python by way of an expanding example program (an archive program). Each introduced Python feature is utilized to add new features to the sample program, including things like a graphic interface with Tkinter and some basic OOP design considerations (some other examples are used along the way, as needed). This is one good approach (not necessarily the only one) for fairly novice programmers, but is a little slow for experienced ones. Despite its virtues, it is difficult to really recommend _Programming Python_ at this point. Being published in 1996, _Programming Python_ feels a bit out of date; Python is a conservative language, and little you would learn is actually inaccurate now, but in the last 4-5 years quite a few new moudles have been added, and even a few important new inherent language features (especially with Python 2, which is not yet in any of the books). However, if rumors of a new edition prove true, this book could get a new life. _Learning Python_ is in some ways a successor for _Programming Python_. _Learning Python_ is also an O'Reilly title, and is also (co-authored) by Mark Lutz. At 365 pages and the same 9.5" x 7" form factor as most O'Reilly books, _Learning Python_ is a quicker read than _Programming Python_. The idea of running one example throughout the book has been dropped, probably in conjunction with aiming slightly less at completely beginning programmers. But _Learning Python_ is still quite gentle as an introduction, with every feature explained in sufficient detail for, e.g., a (bright) high school student who has not previously encountered that programming concept. In strucuture, _Learning Python_ is composed of a series of chapters that build on each other in a logical fashion. Local examples and source code are provided along the way as a way to see each feature in a (limited) real-world context. The tone is conversational, with liberal use of 2nd person and 1st person plural. The editing, as with all O'Reilly books, is careful and consistent. The final chapters throw in bits and pieces of special topics: COM, Tkinter, JPython, etc. These feel a little bit out of place, neither intergrated with the main text, nor quite detailed enough to stand on their own. _The Quick Python Book_ is something like a cross between _Python Essential Reference_ and _Learning Python_. Superficially, it is the size of the latter with the typography of the former. The goal of _The Quick Python Book_ is to serve as an introductory text which simultaneously is usable as a reference to go back to. Topics are organized in subsections, each introduced in a tone that is more descriptive than _Learning Python_, but more conversational than _Python Essential Reference_. A good range of topics are covered: basic language features and standard modules; Tkinter; COM; JPython; OS specific usage. _The Quick Python Book_ aims at a more sophisticated reader than _Learning Python_ does. You can learn Python from the _The Quick Python Book_, but you should start out with some experience in other programming languages. And the index is strong enough that this is a book you can usefully refer back to later. Overall, I would say that if you can only buy one Python book, buy _The Quick Python Book_. That said, if you can buy more than one, _Python Essential Reference_ is better for referring back to, which sort of undermines one of the two goals of _The Quick Python Book_. SPECIALIZED PROGRAMMING TASKS IN PYTHON ------------------------------------------------------------------------ Sometimes what you want is not a general book on Python, but one that goes into greater detail on performing a specific task, or working in a specific environment. Three such titles are available (obviously, they are what you want only if they cover your particular area of interest). _Python and Tkinter Programming_ cover just what you would expect: working with the [Tkinter] wrapper for the 'TK' library (available on many OS platforms). It runs a fairly lengthy 650 pages, but much of that is code samples and screenshots. In the context of learning a GUI library, these screenshots are helpful in visualizing what a widget really does (or a layout, etc). The code is probably a little longer than is really helpful, however. As various [Tkinter] features are introduced, complete little applications utilizing them are given as code samples. But it is unlikely you will actually use Grayson's specific applications yourself, and seeing ten widget of the same type created does not really illustrate much more that seeing one created. That said, Grayson does a good job presenting his subject, and a few extra pages of examples does not really hurt the book. The first 2/3 of _Python and Tkinter Programming_ is narrative in quality, and leads a reader through building the examples. The final 1/3 provides a reference for all the possible [Tkinter] arguments and methods. _XML Processing with Python_ is a quirky book. It presents quite a bit of general introduction to Python (certainly more than the other specialized books), but very little by way of introduction to XML. That is, McGrath's book is useful for XML users/programmers approaching Python, but not nearly as much for Python programmers approaching XML (the title would suggest the opposite to me). Also, _XML Processing with Python_ uses a rather large font, plenty of whitespace, and moderately thick paper--I suspect it has fallen into a "priced by the pound" gimmick of many recent computer-topic books. The other odd thing about _XML Processing in Python_ is the degree to which it pushes McGrath's [pyxie] library as a way to handle XML programming. [pyxie] is actually a very nice concept that transforms XML into a line-oriented--and more easily parsed and processed--format call 'PYX'. The approach is a good one, but probably a lot more programmers will still want to use more standard techniques like SAX and DOM. Fortunately, McGrath does provide reasonable introductions to SAX and DOM as well, but in the end he really wants you to use [pyxie] (which is free software, so it is not a commercial plug). I must confess that I have had less opportunity to evaluate _Python Programming on Win32_ than I have most of the others. I just do not use the Win32 platform enough to have undertaken any real projects for which I would need this book. However, the authors certainly have immaculate credentials: Mark Hammond is creator of the PythonWin IDE, PythonCOM, and Python for .NET. He knows Windows, and he has done a lot for the Python community. In tone, _Python Programming for Win32_ is pretty similar to _Learning Python_. Both are fairly conversational, and lead readers through a logically arranged succession of topics. _Python Programming on Win32_ provides a pretty quick introduction to Python in general, then moves on to working with all the specifics of the Windows platform: COM, ODBC, ActiveScripting, and other aspects. Python makes a really nice fit for Windows, actually; all those chores you might otherwise do in VB or VBScript--scripting MS-Office applications, maintaining the registry and configurations, creating ASP pages for IIS, etc.--are simply easier to do if you use Python instead. _Python Programming on Win32_ is a good introduction to doing this very set of things. RESOURCES ------------------------------------------------------------------------ _Python Essential Reference_, David M. Beazley, New Riders 2000. ISBN: 0-7357-0901-7. _Python Pocket Reference_, Mark Lutz, O'Reilly, 1998. ISBN: 1-56592-500-9. _Learning Python_, Mark Lutz & David Ascher, O'Reilly, 1999. ISBN: 1-56592-464-9. _Programming Python_, Mark Lutz, O'Reilly, 1996. ISBN: 1-56592-197-6. _The Quick Python Book_, Daryl Harms & Kenneth McDonald, Manning, 2000. ISBN: 1-884777-74-0. _Python Programming on Win32_, Mark Hammond & Andy Robinson, O'Reilly, 2000. ISBN: 1-56592-621-8. _Python and Tkinter Programming_, John E. Grayson, Manning, 2000. ISBN: 1-884777-81-3. _XML Processing with Python_, Sean McGrath, Prentice Hall, 2000. ISBN: 0-13-021119-2. _(the eff-bot guide to) The Standard Python Library_, Fredrik Lundh, eMatter (mightwords), 1999. ISBN: 0717350770. For information see: http://www.pythonware.com/people/fredrik/librarybook.htm ABOUT THE AUTHOR ------------------------------------------------------------------------ {Picture of Author: http://gnosis.cx/cgi-bin/img_dqm.cgi} David Mertz' failures as a hunter, fisherman, and shepherd have led him to his life of critical criticism. Tomorrow he may try something else. David may be reached at mertz@gnosis.cx; his life pored over at http://gnosis.cx/publish/. Suggestions and recommendations on this, past, or future, columns are welcomed.