Slashdot Mirror


Learning Python, 4th Edition

thatpythonguy writes "Learning Python is a well-written book by an experienced Python trainer that has served the Python community well since the first edition was published in 1999. Now, at its fourth edition, this book by Mark Lutz arguably continues to be Python's bible." Read on for the rest of Ahmed's review. Learning Python, 4th Edition author Mark Lutz pages 1216 publisher O'Reilly Media rating 9/10 reviewer Ahmed Al-Saadi ISBN 0596158068 summary A hands-on book that will help you be productive with Python 3.0 quickly This book is addressed as an introductory text to programmers new to Python. Although people with no programming experience are not discouraged from reading it, they are warned that time is mostly spent teaching Python, not programming fundamentals. I agree with this picture, though from my own experience and those of others, the book is equally valuable to more experienced Python programmers both as a pseudo-reference and as an introduction to more advanced topics. The critical point here is that the book does not make assumptions about educational or vocational experiences and provides many examples; this renders the book approachable by a large audience.

Both Python 2.6 and 3.x are covered in this edition. However, the latest 3.x line is considered the reference from which variations in 2.6 are discussed when appropriate. This approach is logical; the new Python 3.x presents a major change to the language, but is not sufficiently dominant to warrant exclusive treatment.

This book discusses the Python language and excludes the Python standard and non-standard libraries. The latter are discussed in other places including Lutz's own Programming Python which stands at its third edition at the time of writing of this article. I find this division necessary because of size considerations and, in fact, this division did not exist in the first edition of the book! However, there is one topic that does not seem to fit the language/libraries divide, and that topic is packaging and deployment.

I will argue that there are not many (if any) books that discuss packaging and deployment of Python programs well. I will also argue that this topic should be included in the book being reviewed here since it is so essential to real Python programming. Since Lutz discusses the Python runtime environment, I do not think it detracts from the book's coherence to include a chapter on packaging.It is possible that the proliferation of various packaging and deployment options such as distutils, setuptools, pip, buildout, virtualenv, paver, fabric and others, is the reason for this exclusion. Or it could be that these tools are in a state of major flux that any text will become quickly outdated. If size is the reason for this exclusion, maybe Lutz or someone else can publish 'Packaing and Deploying Python' as a separate volume.

The book starts by building a case for the use of Python. Both the features of the language and its prominent users are discussed to build credibility. Then, the runtime environment is discussed: how to run programs in various ways on various operating systems and language interpreters.

Types and statements, which are at the core of any language, are discussed next. Notably, there is an excellent discussion of the topic of iterators and generators (also discussed in a later chapter). Functions, modules and classes are then introduced. The text also includes a discussion of general object-oriented programming (OOP) principles which I find to be invaluable as it brings the topic of classes to life.

Exceptions are introduced and discussed in detail. The placement here is appropriate since exceptions are now objects in Python so classes had to be discussed first. This chapter should prove to be especially useful for people migrating from other languages that do not have simple, yet effective, exception-handling constructs.

Finally, four advanced topics are covered: decorators, Unicode, managed attributes, meta-classes. I find the first two to be absolutely necessary for almost any system nowadays, even small ones! The atter two are not as ubiquitous, but should be useful to more experienced programmers.

I should mention here that the discussion of the topics discussed above does not stop at the basics but provides comprehensive coverage. This is evident in the discussion of concepts such as dynamic typing, inheritance order, iterators, generators, comprehensions, and functional programming, among many others. There is even an interlude on documentation and the pydoc library.

Like many programming texts, the book uses small programming examples (appropriately executed in the Python interactive shell). The small examples hope to capture the essence of the topic at hand, and that, it does well within the limitations of a small-scale context. But this fourth edition adds a new chapter on classes (Chapter 27) that contains a more realistic code example presented in a tutorial format.

In addition to examples, each chapter ends with a summary of the chapter's content as well as a quiz on that content. The quiz is immediately followed by its answers for easy reference. I have to admit that I do not use any of these two features, so I will not be able to comment on their efficacy.

Like many O'Reilly books, this is a well-written, coherent, and beautifully type-set book. I highly recommend it to anyone who wants to, or already does, program using python. It should help the novice in the transition to an excellent programming language or, otherwise, make an already familiar environment more powerful in the hands of veterans.

Ahmed Al-Saadi is a Software Analyst who works for a Montreal Python house. He wrote his first lines of code on a Sinclair ZX Spectrum+, though unfortunately not in Python at the time.

You can purchase Learning Python, 4th Edition from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

29 of 163 comments (clear)

  1. Cover art by Anonymous Coward · · Score: 2, Insightful

    Soooo the language is called PYTHON and O'Reilly put some kind of rodent on the cover? Not, I don't know... a python?

    Maybe if the rat was being eaten by a snake it would make sense...

    1. Re:Cover art by ultrabot · · Score: 5, Funny

      The rat is there because python is still learning.

      --
      Save your wrists today - switch to Dvorak
    2. Re:Cover art by DragonWriter · · Score: 2, Informative

      Soooo the language is called PYTHON and O'Reilly put some kind of rodent on the cover? Not, I don't know... a python?

      They put a different animal on the cover of each book.

      The python is, IIRC, on the cover of Programming Python.

    3. Re:Cover art by theskipper · · Score: 3, Informative

      A python appears on a previous O'Reilly book, "Python in a Nutshell" (ISBN 978-0-596-10046-9).

      My assumption is that they don't use the same animal on more than one cover, correct me if I'm wrong.

    4. Re:Cover art by K.+S.+Kyosuke · · Score: 2, Funny

      The rat is there because learning pythons need school supplies, too.

      --
      Ezekiel 23:20
    5. Re:Cover art by reverseengineer · · Score: 3, Funny

      Food for thought?

      --
      "FDA staff reviewers expressed concern about the number of patients who were left out of the study because they died."
    6. Re:Cover art by gpuk · · Score: 2, Informative

      IIRC, the python name is a homage to Monty Python and has nothing to do with the snake. Perhaps a knight sans arms would have been more fitting...

    7. Re:Cover art by Hatta · · Score: 2, Funny

      This time they should have used a dead parrot. One with beautiful plumage.

      --
      Give me Classic Slashdot or give me death!
  2. Monty by ulski · · Score: 5, Funny

    Woman: Well there's rat cake ... rat sorbet... rat pudding... or strawberry tart.
    Man: Strawberry tart?!
    Woman: Well it's got some rat in it.
    Man: How much?
    Woman: Three, rather a lot really.
    Man: ... well, I'll have a slice without so much rat in it.

    Why is there a rat on the cover of a snake book anyway? Perhaps O'Reilly already used a snake picture on the cover of some other book and they didn't wanted to confuse people by having 2 snake books?

    1. Re:Monty by bsDaemon · · Score: 2, Insightful

      IIRC, there is a python on the cover of 'Programming Python.' I don't know why they picked a mouse for this, maybe because it was less confusing than picking a second kind of snake? The cover of 'Programming Perl' is, famously, the camel, however the language isn't called camel, so when they put the llama, alpaca and vicuna on 'learning perl', 'intermediate perl', and 'mastering perl' respectively, it was obvious they were related but don't cause any clash due to naming. What does the sheep on 'Perl Cookbook' have to do with anything?

    2. Re:Monty by Cryacin · · Score: 2, Insightful

      What does the sheep on 'Perl Cookbook' have to do with anything?

      Maybe mutton for dinner?!?

      --
      Science advances one funeral at a time- Max Planck
  3. Better Than First Edition? by adipocere · · Score: 4, Insightful

    I sincerely hope that this version is better than the first edition, although anything short of a random re-arrangement of pages would serve as an improvement. The first edition actually delayed my initial use of Python by about a year and a half. I had heard wonderful things about the language so I figured, "Ah, an O'Reilly book!" Big mistake.

    Endless bits about immutability, without hints as to why I ought to care. I can appreciate the use of the interactive prompt now, but to start with it seems ... strange. I was not transitioning to Python from shell programming, and I doubt many do. Lambda expressions, entirely too early. Not a great deal of attention paid to idiom, which is just about central to learning a new language. Little discussion of how you might have accomplished tasks in other languages and wish to do the Pythonic equivalent. I loathed the first edition and refer to it precisely never. I eventually dropped it in a puddle and felt no urgency towards retrieving it. The now-wrinkly cover suggests that some unhappy deity has attempted to purify it by flood.

    I ought to have tried fire.

    1. Re:Better Than First Edition? by kpainter · · Score: 3, Informative
      Programming in Python 3: A Complete Introduction to the Python Language by Mark Summerfield is better IMHO.

      I gave up in the middle of Learning Python 3rd Ed. One of the things I absolutely hated about Learning Python is the author continually telling you about X will be covered later in chapter Y. There is a LOT of that. That and half-way through the book, I still couldn't do anything simple as he hadn't even talked about for loops yet. Too much detail on the finer points of data types and too little "quick start". I got bored with this book.

      I don't doubt that there is a lot of great info in that book. It just isn't organized very well at all. My guess is the 4th ed. is changed to reflect Python 3.x. If it were reorganized, it would probably be really good.

    2. Re:Better Than First Edition? by Monkey-Man2000 · · Score: 3, Insightful

      If not this book, care to share an alternative recommendation or two?

      Well, I can't disagree with the grandparent's very nice flame, but why not start with Guido's tutorial? http://docs.python.org/tutorial/ Between that and the library reference, I was up and running making useful scripts in an afternoon at work one day, but I had previous programming experience. But since this book isn't for people like that, who is it for? Only people I can think of are language lawyers, and there's a free source for that as well! http://docs.python.org/reference/index.html

      --
      This post was generated by a Cadre of Uber Monkeys for Monkey-Man2000 (603495).
    3. Re:Better Than First Edition? by slimjim8094 · · Score: 2, Informative

      I have probably the previous edition of this book, and what you're describing sounds like a different book. Lamda expressions came after basic and intermediate functions - I had no problem with it. All he talked about was idiom - the "pythonic" way of doing things - while mentioning that a C programmer would probably have used a loop instead of a map expression, etc.

      So I'd say they fixed it up a bit.

      --
      I have developed a truly marvelous proof of this comment, which this signature is too narrow to contain.
    4. Re:Better Than First Edition? by mindcorrosive · · Score: 2, Interesting

      Endless bits about immutability, without hints as to why I ought to care. I can appreciate the use of the interactive prompt now, but to start with it seems ... strange.

      The thing about mutability in Python is that it can bite you in the neck if you assume the variable passing and assignment work as in some other popular languages. I can appreciate the author's tirades about this, as he brought his point around, even with simple examples. And how do you propose to start with a language that doesn't have one-IDE-to-rule-them-all, like Visual Studio or Eclipse? You know how sparse is IDLE by today's standards.

      Little discussion of how you might have accomplished tasks in other languages and wish to do the Pythonic equivalent.

      That's why there's this other book, "Programming Python", again by Lutz, where he discusses the practical aspects of Python programming, and using the standard library modules. There are examples of the "Pythonic" way to do this or that, instead of masking C/C++ syntax with Python expressions. The discussions of modules, packages and classes is extensive, and down to the details of how they work and are used.

      I understand your frustration, and can't comment on the first edition that you've seen. I've preordered the fourth edition - this one - (the whole 1000 or so pages), and I found it a very good self-educational tool - I managed to learn most of the ins-and-outs of the language in just one week, without having prior exposure to Python (I've got experience with 3-4 other programming languages, admittedly). I'd recommend it highly for anyone that wants to learn Python (the language) quickly.

      Of course, this is my opinion, so take it as you may.

      --
      + 3.14 Transcendental
    5. Re:Better Than First Edition? by steve.howard · · Score: 2, Informative
    6. Re:Better Than First Edition? by McNally · · Score: 2, Interesting

      A whole brand tarnished on one product out of hundreds (if not thousands)?! You're harsh man!

      Well, here's the thing. I spent most of the years of my career living in a university town with excellent booksellers. I now live in a comparatively tiny island community a long way from the nearest tech center and if I want tech books I can't just pop into a store that has them in stock and browse, I have to order them and have them shipped.

      I've previously bought quite a few O'Reilly titles and while not every one of them was brilliant, they were reliably pretty decent; this one was affirmatively the worst, to the point where in the future when I want a tutorial or reference work on a new technology I won't just call up and order the O'Reilly book on the subject because I don't feel like I can rely on their quality and I don't need any more $40 door stops.

      It doesn't mean I'll never order another O'Reilly tome, but it does mean that I felt let down enough to stop automatically trusting their quality by default.

  4. Re:easy to learn by MaskedSlacker · · Score: 2, Funny

    Then how come only Harry can do it?

  5. Too wordy by milgr · · Score: 4, Informative

    I bought this book about a month ago. I had my doubts about a book this size, and my doubts were realized.

    I learned C from K&R first edition. K&R is about 150 pages (from memory). It covers all of the language succinctly and completely. Actually, it covers most of the language twice - first in tutorial form then in specification form. It is a fine resource.

    Why should a book on Python be over 1000 pages? I started reading this book the same way I read K&R - from the beginning. Unlike K&R, after 50 pages I barely got to coding. Within each section the language is quite verbose. I suspect that the authors were paid by the word or the page.

    On a positive note, I was able to use this book as a reference book as the index is quite reasonable.

    I would recommend this book to those insomniacs who are interested in learning Python.

    --
    Where law ends, tyranny begins -- William Pitt
    1. Re:Too wordy by yerM)M · · Score: 2, Insightful
      I'm being a bit tongue in cheek here, but maybe you are rather missing the point of Python which is "batteries included." The python standard library contains much more than Python, did K&R include:
      • A web server
      • An xml parser
      • Email parser
      • GUI package
      • Windows COM interface
      • And so on.

      It's kind of surprising that Learning python is only 1000 pages, which is not too say that it isn't too wordy.

  6. Re:why? by mangu · · Score: 3, Informative

    I know you are trolling, but here's the answer:

    1) Programming in Python is faster than in C, and Python lets you use C libraries where performance is needed. Python will not make C go away, but will let it be used where it's really needed.

    2) Python is more secure and much more powerful than PHP. With a programming environment like Django, Turbo Gears, or Zope, Python can easily do anything PHP can, but PHP is not even near to doing everything Python can do.

  7. Re:Missed out on Python by navyjeff · · Score: 4, Informative

    I found Python to be a useful language for scripting and accessing C libraries.

    One of the things I like most about it (and others seem to hate) is that it's sensitive to whitespace. This feature has the side effect of making the language more readable and forcing people to indent their code. After programming in Perl, did you ever go back and try to figure out what you did a year ago? I find that my year-old Python programs to be much more readable than my year-old Perl.

    Also, if you're a scientist or engineer, I recommend "Python Scripting for Computational Science". It will get you programming much earlier than Learning Python and is oriented toward mathematical calculation and visualization problems.

  8. Re:Missed out on Python by Manhigh · · Score: 2, Informative

    While I cant speak to php or Occam...

    You aren't forced into object orient programming as with Java, although the language does have good implementations (IMHO) of classes if you choose to utilize them. It also doesn't force the 'one class per file' structure of Java upon you. (Granted its been years since I've touched Java, so these critiques may no longer apply).

    I started by using Python for a lot of the things for which I initially used Perl. I find Python code immensely more readable than Perl.

    Lately I've used Python alot because it has some superb 3rd party libraries for scientific computing (numpy, scipy, matplotlib are the three which I use the most.) These libraries give Python the utility of Matlab (vectorized functions, easy plotting, interfacing to C and Fortran for speed) in an open platform without the fees associated with Matlab.

    For my job (aerospace engineering) Python is now my go-to language when I first start working a problem, and I transition to C or Fortran only if I need the speed or someone else requires me to do so, which is not often these days.

    --
    "Open the pod by doors, Hal" > "I'm afraid I can't do that, Dave" sudo "Open the pod bay doors, Hal" > alright
  9. JS vs. Lua by tepples · · Score: 2, Interesting

    JavaScript is such a hack, and such a pathetic excuse for even a scripting language.

    What makes JavaScript so much more of a hack than Lua? Both use prototype-based object systems. Perhaps your complaint is with the HTML DOM, but that would be the same whether you used Lua, Python, or JavaScript on top of it.

  10. Wear gloves. by NeoSkandranon · · Score: 3, Funny

    Carpet pythons, like I own, are bitey bastards. I hope whatever python you learn about in this book is a little more friendly.

    --
    If you can't see the value in jet powered ants you should turn in your nerd card. - Dunbal (464142)
  11. The Bible? Bad Analogy... by happy_place · · Score: 2, Interesting

    O'Reilly "Learning X" (fill in X with your programming language of choice) are not "BIBLE"s. They're learning texts. For the real meat of the language, decent reference and altogether comprehensive understanding of life and the universe, you'd want to pick up O'Reilly "Programming X" books. So in this case, Programming Python would be a Bible, a book you return to again and again. The Programming series of books, for most experienced programmers is generally just as good a place to start learning the language, and you don't need the Learning series.

    --
    http://www.beanleafpress.com
  12. Re:Question: Who's making a living coding Python? by thatpythonguy · · Score: 2, Interesting

    I (the author of this review) use Python exclusively (if you don't count specialized and supporting languages). If you are looking for high-profile users, try Google. Python is one of three "officially supported languages" (the others being C++ and Java; "official" does not mean that other languages are not used!). I would guess that all other large software houses use Python somehow. Besides being a great language in its own right, it is a great systems/prototyping language! Also, it is perfect if you like to code without undue pain ;)

  13. Re:Missed out on Python by binary+paladin · · Score: 2, Interesting

    Disclaimer: I love Python.

    That said, I love Python IN SPITE of its way of enforcing white space. I've had many annoying debugging issues that are the result of whitespace being broken when moving from one editor to another and it makes using blocks inside the interactive shell more annoying than it needs to be.

    Most of my coding these days is in Ruby and while it doesn't enforce how you use whitespace, only a complete tool doesn't indent their code. I find that having some keyword or symbol (e.g. end or }) also makes code easier to read than just ending as a result of the indent dropping (which is not easy to see in some cases and is even more annoying if you have to use an editor without some way of visually denoting line breaks and tabs).

    The Zen of Python should be followed by virtually every language out there though. There isn't a language on the planet that wouldn't be more readable if those conventions were followed.