Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Book Review: The Python Standard Library By Example

samzenpus posted about 3 years ago | from the read-all-about-it dept.

Python 33

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.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.

cancel ×

33 comments

Sorry! There are no comments related to the filter you selected.

WTF? (-1)

Anonymous Coward | about 3 years ago | (#37146592)

How is it possible to review a book that was not published by Packt? Even if it is possible, why bother? Slashdot, what has happened to you? I, like many others, come here solely for the latest and greatest information on Packt? This non Packt book review has crushed my soul and made me cry. Does anyone else like Packt? Because I love reading Packt books. If anyone wants to know more about Drupal, I suggest they pick up the latest Packt book on Drupal, because no one can teach you Drupal like Packt can.

Re:WTF? (0)

Anonymous Coward | about 3 years ago | (#37146988)

If anyone wants to know more about two major versions old Drupal, I suggest they pick up the latest Packt book on two major versions old Drupal, because no one can teach you two major versions old Drupal like Packt can.

FTFY.

One problem with Python's standard library... (3, Informative)

c0l0 (826165) | about 3 years ago | (#37146606)

... 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!

Re:One problem with Python's standard library... (2)

dkleinsc (563838) | about 3 years ago | (#37146912)

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.

Re:One problem with Python's standard library... (1)

loufoque (1400831) | about 3 years ago | (#37151530)

For instance, strcpy is still supported in C, even though it's widely regarded as very unsafe.

There is a difference between a function imposing a precondition and one that is broken.

Re:One problem with Python's standard library... (2)

Dorkmaster Flek (1013045) | about 3 years ago | (#37147260)

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.

Re:One problem with Python's standard library... (1)

ThorGod (456163) | about 3 years ago | (#37147488)

Until you realize that 1 problem solved is worth (at least) 200 good and 1000 decent ideas.

Another thousand page book of examples (2)

Animats (122034) | about 3 years ago | (#37146634)

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.

Re:Another thousand page book of examples (3, Insightful)

chicagotypewriter (933271) | about 3 years ago | (#37147026)

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.

Re:Another thousand page book of examples (4, Interesting)

mvdwege (243851) | about 3 years ago | (#37147364)

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

Re:Another thousand page book of examples (0)

Anonymous Coward | about 3 years ago | (#37148694)

The python documentation is by and large awful.

Thank God I'm not the only one who thinks this. A couple of years ago I tried to learn Python by starting with the standard Python documentation. After five or six dense pages of how to add two numbers together, I gave up. It wasn't until four months ago when I had to learn Python as part of my job that I even came close to learning anything about it, and I certainly did not do it with the Python documentation.

For what it's worth a lot of "new" languages fall into this trap: they assume that anyone starting with the language is starting with it as their first language, and always start with the most mind-numbing things (Like math, or printing a string...). Except that's almost never the case: most people learn one language after another, and really only need a primer on the basic syntax, with some examples, and a good language and library reference.

Re:Another thousand page book of examples (1)

DocHoncho (1198543) | about 3 years ago | (#37149834)

Personally I've found the documentation to be hit or miss. Some modules provide good examples in addition to API docs, while others just give a description of the API with one or two pathetic examples that don't even demonstrate a real-world use of the code. All in all I find the documentation to be very good, but there's always those particular modules that you pretty much have to figure out everything yourself... logging, i'm looking at you..

Re:Another thousand page book of examples (2)

mvdwege (243851) | more than 2 years ago | (#37152966)

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

Re:Another thousand page book of examples (0)

Anonymous Coward | more than 2 years ago | (#37191962)

Even though i don't know what are you guys talking about,but i like the atmosphere here and i like the website ,besides,here,my website in china,lepuwang:http://www.leepliya.com welecome to my website to shopping and welcome to china.

Re:Another thousand page book of examples (0)

Anonymous Coward | about 3 years ago | (#37148546)

It might be interesting to see if the book could be offered as 13 fascicles at 100 pages. But the content of this book is golden however it's presented.

Since it's not by Packt... (0)

turkeyfeathers (843622) | about 3 years ago | (#37146658)

...it can't possibly be of interest to Slashdot readers. I'm saving up for Packt's not-to-be-missed book on Bitcoins.

Re:Since it's not by Packt... (1)

HarrySquatter (1698416) | about 3 years ago | (#37147022)

Or the newest Packt book: 'Programming with Python 2.5'.

Re:Since it's not by Packt... (1)

istartedi (132515) | about 3 years ago | (#37147564)

newest Packt book: 'Programming with Python 2.5'.

They're hiring for that; but only if you have at least 10 years experience.

Re:Since it's not by Packt... (1)

Tipa (881911) | about 3 years ago | (#37147804)

I can't figure out if you used "for all intensive purposes" ironically, or if you really don't realize it's "for all intents and purposes".

Argh.

Re:Since it's not by Packt... (0)

Anonymous Coward | about 3 years ago | (#37149024)

It leads to a lot of other questions, doesn't it?

Re:Since it's not by Packt... (0)

Anonymous Coward | about 3 years ago | (#37147574)

I was just in the market for getting a nice Python reference. Then, like many times previous in my life, Slashdot placed a relevant article in my lap. Thanks again. Stay classy Slashdot.

non-"Standard" relationships would've been nice (2)

smoothnorman (1670542) | about 3 years ago | (#37146910)

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.

Another language, another stdlib... (0)

Anonymous Coward | about 3 years ago | (#37147504)

Anyone who took calculus remembers the table of integrals that was inside the front cover. Why not a table of functions?

At this point in the history of computing, we ought to have something like a dictionary of functions in common use. Aside from language barriers there are a few other issues which are, IMHO, solveable.

The type issue is one. We would also need a set of standard types. Each entry in the dictionary would have a list of common type signatures.

A simple example:

Divsion. Standard function no. 89. Common type signatures: i32:i32,i32. Exceptions: division by zero.

This raises the issue (no pun intended) of describing exception classes across languages but I don't think it's insurmountable either.

When computer engineering is a mature discipline, we should have a DB (in the old days there would have been a big heavy book) of functions. "I see you used standard GUI function 4076 with Window type 6 returning i32, was there a reason to deviate from the more common practice of returning u32, which is listed first in the reference?".

Re:Another language, another stdlib... (1)

buanzo (542591) | about 3 years ago | (#37147912)

I think that the BEST online help I even got from a programming language was turbo pascal's help. Organized both by task, library and alphabetically. I miss something THAT useful.

Re:Another language, another stdlib... (1)

spiralx (97066) | about 3 years ago | (#37147980)

After starting off with GFA Basic on my Atari ST, the next language I learnt was Turbo Pascal, which I learnt entirely from the help files... as you say, they were amazingly useful, even for someone like me with minimal experience and none in compiled, statically-typed languages.

Python Module of the Week (4, Informative)

jnik (1733) | about 3 years ago | (#37148030)

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

Re:Python Module of the Week (1)

lophophore (4087) | about 3 years ago | (#37149292)

The PMotW is a great resource for novice Python programmers. I use it quite a bit. I'm sure this book is every bit as good.

Sadly (for authors and publishers) using the Oracle of Google is faster than flipping pages.

serious factual inaccuracy (1)

ag_123 (1698048) | about 3 years ago | (#37148822)

The Slashdot reviewer writes:

"The book addresses itself to intermediate Python programmers and covers versions 2.7 and 3.x of the language."

Umm... no it doesn't. As anyone who has an amazon account can verify, the author does *not* cover Python 3.x. This is what Doug Hellmann says at the bottom of p.1 and the beginning of p.2 in his book:

"Although the current transition to Python 3 is well underway, Python 2 is still likely to be the primary version of Python used in production environments for years to come because of the large amount of legacy Python 2 source code available and the slow transition rate to Python 3. All the source code for the examples has been updated from the original online versions and tested with Python 2.7, the final release of the 2.x series. Many of the example programs can be readily adapted to work with Python 3, but others cover modules that have been renamed or deprecated."

This is seriously hurting the reviewer's credibility. How likely is it that he read through 1300 pages and didn't even understand which language the book was written in?

Re:serious factual inaccuracy (1)

thatpythonguy (1726724) | more than 2 years ago | (#37158060)

Granted, the choice of words is vague and the concept of coverage needs elaboration. Despite the distinction that is often made between the 2.x and 3.x branches, some features appear in minor versions belonging to each of them. Specifically, many of the features that were originally intended for 3.0 were back-ported to 2.6 as described in What's New in Python 3.0 [python.org] . In fact, there are library components in 3.0 that were later deprecated in 3.1!

I suppose I was paraphrasing the author's statement about his attempt to write future-proof code (as much as possible), so that most of the code could run unmodified or with minimal modifications. If you understand coverage as such, then there will be no confusion. However, if you understand coverage as the ability to write code that will readily run on both versions (having been tested on both), then you are right in pointing out the discrepancy.

As to the last comment, I surely did not go through an exhaustive proof-reading of the book à la peer review! I don't know about you, but I don't have that much free time to spare on such an adventure, so no, I didn't go through the 1300-page book, looking closely at the statements and library calls to know which versions of Python it covers (2.5, 2.6, 2.7, 3.0, 3.1, or a subset). My aim was to describe the structure of the book and overall place within the literature as well as the benefits that it may endow a programmer to carry out development activities.

Useless. (1)

jfz (917930) | about 3 years ago | (#37149106)

Since parts of the python standard library can dramatically change every x.x release. I found learning to apply and maintain code written in the "standard library" to be cyclical hell in a hand basket. Much of the documentation these days is along the lines of: No, usage of this or that feature was deprecated. No, though not documented, it's done this way now. No your getting this error because.. well.. we don't know, its ether 2.5, 2.6, or 3.0, figure it out. Given this experience, I don't see how a dead tree covering a particular one is of all that much value. To me a selling proposition would be one which provides a continuity in documentation with fully explained use-cases of features after 2.5- for those of us who have had to pick up the language and deal with the mess of non-versioned code. A mess that whether the authors of the language like it or not, do have a hand in being responsible for.

typesetting is terrible (1)

HunkaHunkaBurninLove (411198) | more than 2 years ago | (#37152230)

The review is spot on about the typesetting in the book; it is terrible and is a deterrent to enjoyment and utilization of the contents. I've never had this reaction to a book before; I'm not really a font-obsessive kind of guy. They would have been better off just sending the humongous PyMOTW PDF to the printer.

My favorite Python reference is Python Essential Reference (4th ed) by Beazley; it pretty much lives up to its title. Among other things it is good at identifying points where Python2 and Python3 diverge.

Good review (1)

YGingras (605709) | more than 2 years ago | (#37153798)

This is a very good review, Ahmed. Thanks for sharing!

do you want to rejuvenate? (0)

Anonymous Coward | more than 2 years ago | (#37154494)

Stop the effects of aging. Log in to our site and learn how to achieve stoping aging. Forget the fatigue and lack of energy. Retard up the natural process of aging.
Get all the benefits of a natural revitalizer that one you are needing.

Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>