Slashdot Mirror


Book Review: The Python Standard Library By Example

thatpythonguy writes "Addison-Wesley publishers has released The Python Standard Library By Example, another Python book that strategically fits in between programming cookbooks and library reference manuals. It brings the Python standard library that much closer to Python programmers and helps make them more proficient in their trade." Read below for Ahmed's first Slashdot review. The Python Standard Library by Example author Doug Hellmann pages 1344 publisher Addison-Wesley Professional rating 8 of 10 reviewer Ahmed Al-Saadi ISBN 978-0-321-76734-9 summary A unique guide to the Python standard library that is between a cookbook and a reference manual There has been an explosion in the availability of published titles for the Python programming language in the past few years. This has been driven by the rising popularity of this multi-paradigm language that has proven useful in domains spanning web, games, graphics, financial, science, automation and others. Many large and small corporations, universities and governmental organizations are using Python in their respective fields with seeming success.

One of the main reasons for the success of Python is the quality, breadth, and depth of its standard library. Unfortunately, this library is not documented sufficiently in titles that serve as introductory or reference material due to the nature of introductory texts that deal with the basics; on the other hand, reference texts are often too concise and lack sufficient examples. The title at hand is a library-centric tutorial/reference that can be a great tool when you need to learn how to solve certain problems using Python.

The book addresses itself to intermediate Python programmers and covers versions 2.7 and 3.x of the language. Although an experienced programmer coming from another language can learn a lot about Python by reading this book, I personally favor the traditional top-down, gradual method of learning a new language which involves an introductory, tutorial-style, and verbose introductory book. However, realizing that others might not like my cup of tea, I can envision, for example, someone familiar with socket programming picking up this book and writing a network application without prior Python experience. He or she might still need to look up language features on the way, but that should not be too hard as the language is easy to understand and there is a rich library of on-line (and printed) content for basic language constructs.

This title comes in a hefty 1300-plus-page, soft-cover book (or eBook) that is organized around thematic grouping of library modules. The groups are: text, data structures, algorithms, dates and times, mathematics, file system, data persistence and exchange, data compression and archiving, cryptography, processes and threads, networking, the Internet, email, application building blocks, internationalization and localization, developer tools, runtime features, language tools, modules and packages.

Each group contains the relevant modules from the standard library. For example, the text group contains the string, textwrap, re and difflib modules. Each of these modules is briefly described first and then its use is demonstrated in various ways under an appropriate heading. For example, the socket module (networking group) has sections covering addressing, TCP/IP client/Server, UDP clients/servers, UNIX domain sockets and multicast, among others. The code is written in such a way as to focus on the topic being discussed while not overlooking good practices such as wrapping a socket connection call with a try/finally block to ensure that the connection is closed in case of error.

A more advanced module, that is also described in the networking group, is SocketServer. This is a higher-level (on top of the socket layer) facility that enables the creation of network servers (e.g., HTTP or AMQP). It is nice to see that the book demonstrates the creation of an echo server using this module while incorporating more advanced topics such as threading and asynchronous I/O which are necessities in real-life, production code.

Although the content covers quite a bit of ground that surpasses many other sources in terms of coverage, the Python standard library is so vast that any one-volume book attempting to provide comprehensive coverage will necessarily fail! Nonetheless, you will find at the end of each section pointers to other material such as on-line resources, RFCs, and related books that can be used for a deeper study of the relevant topics.

I think that the text could use some typographical features to enhance the clarity of the content. These include highlighting the code using indents or an alternative font to set it apart from the text that surrounds it as I found it hard to visually distinguish the two. The code should also have the name of the file at the top of the listing so that when that name is used subsequently to invoke the code, it would be easy to reference the file contents. Also,I find the general typesetting not as pleasing nor as easy to read as titles from certain other publishers. This latter point is somewhat subjective and, in any case, does not detract from the utility of the content.

Despite the caveat above, I have to say that I like this class of documentation that is between a cookbook and a reference manual. I find it useful that the examples are not so terse nor overly verbose. I also appreciate the quality of the code and the references for further readings. I think that this book fills a void that will make many Python programmers more proficient.

Ahmed Al-Saadi is the Principal Software Consultant for Solea Research, a software consultancy and development company based in Montreal, Canada. He spends his free time writing, contemplating software architecture and playing his Flamenco guitar."

You can purchase The Python Standard Library by Example from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

9 of 33 comments (clear)

  1. One problem with Python's standard library... by c0l0 · · Score: 3, Informative

    ... is that it's there (and I think it's actually great and indeed vast), but it's of seemingly little use in "production" code. The aforementioned SocketServer, for instance - try asking in #python on freenode how to do this-and-that with it. Answer: ditch it, noone uses it because it's crap, use twisted instead. It seems like a solid chunk of the provided functionality is being dragged along for (mostly) historical reasons, as you're supposed to use some third-party library that doesn't come bundled with the Python runtime by default anyway if you want to do actual stuff with the language that's ready for "the real world".

    I still like programming in Python a lot though, and I do make extensive use of the "batteries" it includes. Will probably pick up the book; thanks for reviewing!

    --
    :%s/Open Source/Free Software/g

    YTARY!
    1. Re:One problem with Python's standard library... by dkleinsc · · Score: 2

      In other words, the third-party library playground is larger and moving faster than the standard library. I'd expect that in any code base, because the standard library out of necessity has to be more concerned with backwards compatibility so that the next language upgrade doesn't break existing code. For instance, strcpy is still supported in C, even though it's widely regarded as very unsafe.

      But you'll notice that the Python standard library slowly adds in third-party modules that are widely used and are best-in-class, and slowly kicks out older modules that suck. For instance, the string module has very little left in it that's not deprecated.

      --
      I am officially gone from /. Long live http://www.soylentnews.com/
    2. Re:One problem with Python's standard library... by Dorkmaster+Flek · · Score: 2

      I do like twisted a lot, but with regards to SocketServer, I can tell you that the company I work for uses it in production applications and it works quite well for us. I supposed twisted is easier to work with, less that you have to do by yourself, etc. But if you're limited to the standard library, it works just fine.

      --
      I like to think of online DRM as something akin to a college -- you pay for lessons until you learn something.
  2. Another thousand page book of examples by Animats · · Score: 2

    Yet another unneeded thousand page book of examples. The Python library documentation isn't bad, as such things go. Nor is the library that complex. Most of the library modules are independent of other modules, and have APIs of modest size. Another giant cookbook is unnecessary.

    There are too many of these morbidly obese programming books out there. Little pamphlet-sized books would be more useful. Printing long code examples on paper is just silly; programmers who want to cut and paste need an online version.Those plastic cards which cram what you really need to know on one sheet would be even more useful for many programs.

    1. Re:Another thousand page book of examples by chicagotypewriter · · Score: 3, Insightful

      The Python library documentation isn't bad, as such things go.

      True, the documentation isn't bad. However, example code is almost entirely missing in most cases, which is where this book comes in. It's not a documentation replacement, it's a supplement.

    2. Re:Another thousand page book of examples by mvdwege · · Score: 4, Interesting

      I must disagree. The python documentation is by and large awful. It is often not more than a summation of available objects and methods, with very little explanation and few examples.

      And I suspect it's a cultural thing, as the documentation of third-party modules is often not any better than this mere boilerplate style.

      For shits and giggles, try to compare the docs of the DB API 2.0 (a single short PEP) to Perl's DBI (extensive and with examples).

      I really like Python, but for daily work I've given up on the constant struggle to find just how the heck to use a certain module.

      Mart

      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
    3. Re:Another thousand page book of examples by mvdwege · · Score: 2

      Worse, the python docs are often full of the wrong sort of information. Look at that DB API 2.0 PEP: it spends a full page listing and describing possible exceptions, right at the start of the document.

      I don't want to know that. When I'm scripting something against a database, I want to know how to connect, and how to safely build a parametrized query. List the exceptions at the point where they make sense, not right in front of the real material.

      It's the same disease visible in the sudoers manpage. Instead of giving a short summary explanation with examples first, you get a theoretical treatise on their particular modified Backus-Naur form. Python devs seem to like theorising, as their documentation shows the same model.

      And to make things worse (also answering the guy below): the docs that do exist are not in a standard place. You either need an active HTTP connection to look things up on the web, or it is somewhere in /usr/doc/ or /usr/share/doc, or you have to print the docstrings of every member of __dict__ yourself.

      Perl module documentation gets built as manpages as a standard. Install a Perl module, you get the docs in one go. I'm willing to suffer a little of Perls warts (like the references syntax for complex data structures) for the ease of use of its modules.

      Mart

      --
      "I know I will be modded down for this": where's the option '-1, Asking for it'?
  3. non-"Standard" relationships would've been nice by smoothnorman · · Score: 2

    I realize at 1300 pages that it's already swollen and that they're not part of The Standard Library, but -some- mention of often used, substantial, and useful packages like Twisted or BeautifulSoup, and their relation to The Standard Library would've been nice to see.

  4. Python Module of the Week by jnik · · Score: 4, Informative

    This is the book of the blog Python Module of the Week, so you can get a look at the content there.