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.
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.
Y'know. Just trying to keep up with the current trend.
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...
Woman: Well there's rat cake ... rat sorbet... rat pudding... or strawberry tart. ... well, I'll have a slice without so much rat in it.
Man: Strawberry tart?!
Woman: Well it's got some rat in it.
Man: How much?
Woman: Three, rather a lot really.
Man:
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?
you should call it a $la$hverti$ement. That would make you even more right.
It's hard to believe that's how Micronians are made. Why don't we see it right now by having you both kiss one another?
Ruby failed to make a dent in Python popularity, despite the rails fad over the last few years. Lua isn't really a match for either python or ruby.
Javascript may be the black horse here, because it serves an unique niche and is starting to get adoption outside that niche.
Python in a Nutshell and Python Cookbook. Both discuss that deployment stuff, for example. Neither of them is geared towards complete beginners to programming though. They are very good if you're experienced with some other language and have picked up the basics of Python from the online tutorial.
Learning Python is not a terrible book, but (except for the rather inconvenient matter of being about a pathological eclectic rubbish lister instead of being about Python) Learning Perl does a better job of accomplishing similar goals (explaining programming to non-programmers starting from scratch).
Sadly, JavaScript seems to have become the fad language lately.
A lot of people who can only handle front-end web development thought Ruby would let them do something a bit more serious, so it had a pretty large hype wave while they were trying it out. But they've found even it too difficult, so they've abandoned server-side work in favor of client-side coding again. Unfortunately, this has to be done in JavaScript, since that's basically the only language supported by all major browsers.
It's a shame that we don't have Lua or Python in the browser instead of JavaScript. It'd make web development much more efficient. JavaScript is such a hack, and such a pathetic excuse for even a scripting language.
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.
Yes, but where is the chapter on how to do the dead parrot sketch?
i learned python - look - heres how you say hello:"sssssssss" and goodbye "ssssss". snake talk is easy.
This is a space:
This is a tab:
Learn to recognize them, you'll be using a language where they're semantic.
Way to be a douchemonger. Like, seriously. You respond with a bunch of sarcasm THAT GETS NOWHERE FURTHER THAN THE GP and then use some tone to imply that you are God or something. Your post sickens me. Scum like you need to stop posting or be wiped out of the gene pool. Amen.
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
Phones too. Seems to be the "universal" scripting language.
---
Python Programming Feed @ Feed Distiller
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.
just like you said... where c is "really needed" it still must be used. whereas everything else php does in a much more flexible fashion. the flexibility is the root of all attacks on php because it allows morons to do things the wrong way if they choose. it also allows geniuses to implement procedural processes much more elegantly.
python is pointless.
So A asks a reasonable if cynical question about a practice that is commonplace today (sponsored reviews, astroturfing, etc), B mocks him while contributing nothing to the conversation, C decides to call bullshit on B, and now that qualifies C as having "implied his status as a deity" to paraphrase you. I'd ask you to back that up with some logic but we both know you can't.
I sure wish you immature pantywaists would learn how to separate your bitchy, irritable, pathetic emotional reactions from reasonable behavior. And yeah, getting that pissy and wishing the death ("wiped out of the gene pool") of someone merely because he posts something you don't like qualifies as bitchy. Well actually I should not insult bitches like that. My bet? I think you're stoolpigeon and this time wanted to be a bitch without getting negative karma. In which case the post sickened you because it's true and you wish it weren't. Does it hurt, being not man enough to admit your post contributed nothing and instead trying to cover it up by wishing the death of a stranger?
Ain't it funny how the one who gets so offended because he thinks someone pretends to be God is the same person who feels qualified to decide who should post, reproduce, or even live? Nah, nothing hypocritical about that. Oh i'm sorry, was that too sarcastic for you?
... you can go here and start learning the other Python.
"I came in here for an argument!"
"Oh, oh, I'm sorry, this is abuse."
You can see I've been studying. :-)
Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
Is this edition 500+ pages too? the last one is like a boat anchor.............
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.
I liked this book (at least first ed., the one I read).
This book made me love Python. But I found it too hard for my colleagues at work (most of them biologists who were never exposed to programming), so I decided to write my own book (tinyurl.com/biopython )
I think "Learning Python" is a must have for the seasoned programmer who wants to learn Python.
DNA in your Linux: DNALinux
This is. Don't confuse people. Its also not the idiot's guide, for dummies.
I understand its a figure of speech, but its not a very good one and may confuse people with a different product.
Meh, I was thinking the same thing myself, but I didn't want to waste the time replying. Here's a little article I found on people incessantly telling each other to die in a fire, etc. In other words, don't take it seriously. It was posted by some guy taking a smoke break and needed a little laugh. You're going to get a heart attack from the stress inflicted upon you by people telling mild jokes. Take a chill pill and relax.
"...everything else php does in a much more flexible fashion...."
"...it also allows geniuses to implement procedural processes much more elegantly."
Let me guess, you are 15?
I mean, exclusively coding in Python? Who's got a paying job? Just curious.
Please do not read this sig. Thank you.
I'm calling bull shit on that one.
Do you even lift?
These aren't the 'roids you're looking for.
I am 7. And I will have your job when I am 15.
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)
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
You've convinced me. The world only needs two programming languages, and by miraculous coincidence, those two just happen to be The Pair, and anything other than those two is totally superfluous.
There. That's what you wanted to hear, right?
...would have been a better cover art image?
well... if you're saying that python is good because it can use c libraries, but c is still required for some things, then that doesn't really matter... c can still use c libraries, and is better at doing it, and you can't not use c.
so "python is better because it's faster to code than c"... first off i don't believe that, but even if it were true, i can confidently say that it's faster to code in php than ANYTHING. if you don't need classes or types or constructor functions or static main voids you don't use them. you just alter the data you need to alter. nothing else. so if you want fast coding you have php.
if you think python is the answer, you are kidding yourself.
I'm not sure it's worth it to mix Python 2.6 and 3.0 in the same book. Of course there's always the possibility that you will inherit some code from either version, but in the course of learning the language I think it's best to pick one path and stick with it. I teach introductory programming with Python and we have stuck with 2.6 at least until most resources catch up to the 3.0 changes.
Computer language wars have existed since COBOL, it's a matter of personal preference as much as anything. For the most part run-time interpreted languages do the job, which allows for a near infinite number of languages to proliferate. It's pretty simple, some people prefer the flexibility of Perl, some want a bit more from that, then we get Ruby. You have C which begat C++ and Obj-C which cross-breeded and spawned Java and C#. Not even to get into functional derivatives, or prototypal languages.
The only moron here seems to be the one supporting PHP as a better alternative to anything. PHP's implementation is inconsistent at best, and irritatingly obtuse at worst. It does nothing to bring libraries into language constructs, and doesn't even attempt to have any consistency in its' own methodology. It is/was and shall continue to be an ad-hok wrapper around a few C based primitives.
Michael J. Ryan - tracker1.info
Screw that - go with D. Performance *and* syntactical sugar. Two great tastes that taste great together.
Exactly how much productive work have you done in Python? Because if you think anyone can output code faster in C than Python, you kind of sound like you've never used python.
"if you think python is the answer, you are kidding yourself."
You'd better tell Google that, maybe they'll start porting all their Python over to PHP?
There's no issue to address when dealing with a troll.
A good example is the fact that the sentence above is wasted on you.
It's hard to believe that's how Micronians are made. Why don't we see it right now by having you both kiss one another?
I learned python out of the first edition of Lutz and Ascher. I just pulled out my copy for the first time in years. The last page number is 366. I use Beazley's "Python Essential Reference" almost daily. Not having taught python and not having learned it twice from two books, I don't have much to say about what would be a better introduction. I recommend python the language and Beazley's book. I never found Lutz and Ascher's book (first edition) useful as a reference.
I read the 3rd edition when I first started messing with Python and it's a GREAT book.
In fact, if I was teaching kids to program, this book would be my starting place. It's well written, easy to understand and just a good general introduction to programming in general.
For those reading the criticisms of this book and looking for an alternative... I have been working my way through this book. It is excellent. It's the book I wished I'd had when I tried CS years ago:
http://www.amazon.com/Python-Programming-Introduction-Computer-Science/dp/1887902996
It is very interesting to see the interest and trends based on book sale volume. The state of the computer book contains this interesting chart. For more details see O'Reilley Radar. This was published mid-year 2009. Maybe this new edition might tip the scale.
Since MS is putting all their eggs in c# (and c,c++) it isn't surprising to see the interest. Of note, the impressive rise in Actionscript likely due to web based animated ads.
Views expressed do not necessarily reflect those of the author.
Of course, I forgot to mention the sudden interest in objective-c thanks to Apple.
Views expressed do not necessarily reflect those of the author.
why should a language do anything to bring libraries into language constructs other than allowing for user defined namespaces, classes, and methods? you want to overload math operators some more? they don't "attempt" to have "any" consistency?? "ANY"? i see lots of consistency... did they not attempt to do that?
By consistency I mean in terms of naming, and parameter conventions. Having all extensions as top-level functions is BS to begin with. I really don't need to elaborate on this, if you google for: Why PHP Sucks you will get far better worded reasoning than I will give in this ./ comment.
As to bringing libraries into a language's semantics, it is to provide a better developer experience. There are many cases were a given underlying system interface is exposed in a platform/language specific way. PHP's extensions and even language features are horribly inconsistent as they are.
I will say there are a handful of nice frameworks that will work within PHP, that doesn't mean the core of PHP doesn't have its' own issues.
Michael J. Ryan - tracker1.info
I was formally trained using assembly language. My first high-level language was Basic Plus (DEC). So Perl is just too sexy for me. I can't help using it. Statements like:
open my $file, "name" or die "Error";
or
print $the_report_line unless $no_space_on_page;
Are great!
It is the only language so far which I'm able to write small scripts with no syntax errors.
Views expressed do not necessarily reflect those of the author.
You mean the iPhone. Without it there would be no spike in interest in Obj-C.
I had the first edition of the Learning Python book and didn't find it that useful. The old 1.5 version of Python Essential Reference was way better. Even being new to programming, I found it very readable. I expect the new versions are just as good. It's clear and concise; the chapter on classes is 6 pages, but taught me everything I needed to know. It's one of the few dead tree resources that I still refer to. From total noob to 10 year veteran that book's served me well.
... also, I can kill you with my brain.
A Byte of Python is also a good download-ablebook.
I'd like to buy homeland for our 10 million people. http://twitter.com/mahadiga
and there i was, thinking the last bit of sense had dripped out of the interwebs, good post! :)
i do see dangers in separating emotion from reason though, sure it leads to problems with emotionally scarred people but too much reason and this place would be about as fun as the contents of my sink
always likes snakes, just out of interest, how much force is there in a bite from one?
if (!signature) { throw std::runtime_error("No sig!"); }
Lutz rocks the house. I would have given it a 10.
Where can the book be downloaded?
Dawson, M. “Python Programming for the absolute beginner” 2nd edition. ISBN 1-59863-112-8
Note I said n00bs.
No, I don't get paid to say this.