
Ask HN: ______ is to Python as K&R is to C? - HedgeMage
I'm in need of a book recommendation for learning Python (not learning <i>programming</i>, just adding this language to my repertoire).<p>My learning method is more "start coding something, and refer to a reference book frequently" than "do these lessons and you'll eventually learn enough to start coding something you actually care about".  A good <i>reference</i> is dense and to the point; it makes it quick and easy to look up both the syntax of individual features, and the thinking behind them.<p>Basically, my ideal programming book is Kernighan and Ritchie's "The C Programming Language" -- I want that, but for Python.
======
angrycoder
All the books recommended so far are good books, but none of them really
answer the author's question. In particular, Learn Python the Hard Way is
pretty much the exact opposite of what he is looking for.

The closest thing to K&R C for python is Python Essential Reference by
Beazley. The structure mirrors K&C. The first chapter is a "tutorial
introduction", basically a quick survey of the language, followed by about 150
page explaining the language. It is dense and terse and to the point. The
remaining 400 pages are a reference for the python library.

~~~
thurn
Why, in 2011, are people still selling books with hundreds of pages of
reference material in them? Has anyone needed or wanted to consult a printed
reference on the Python standard library in the last decade?

~~~
dwolfson20
I could write a book just answering this question. I find that most online
reference sites, while extremely useful, lack a certain style, as well as, you
know, in-depth treatment of language concepts.

~~~
billswift
It is also harder to flip back and forth between 2 or more screens to check
related details than it is between multiple pages. Unless you are just
checking a fairly specific, narrow detail, books are just more efficient in
time and effort.

------
thirsteh
The official Python, <http://docs.python.org/tutorial/>, written by Guido van
Rossum himself, is one of the most concise introductions to Python I've read.
Just skip the first few chapters.

Other good books are:

* Learn Python the Hard Way -- <http://learnpythonthehardway.org/index>

* How to Think Like a Computer Scientist/Think Python (now Python for Software Development) -- <http://www.greenteapress.com/thinkpython/>

Dive Into Python is good, but IIRC (from Dive Into Python 2), Mark Pilgrim
tends to use very convoluted solutions to simple problems. The solution might
be superior in terms of performance, but don't always help you learn the
language.

~~~
derrida
If you know how to program allready I really don't recommend 'Learn Python The
Hardway'... it might bore you.

------
ScottBev
I end up going back to "Dive Into Python" for reference.
<http://diveintopython.org/>

My other two references are the Python Standard Library Docs
(<http://docs.python.org/library/index.html>) and StackOverflow.

~~~
arasraj
Dive Into Python would be perfect for the OP's requirements. I touches on many
aspects of python with code samples and is done in a concise way.

~~~
Luyt
Zed Shaw disagrees: <http://oppugn.us/posts/1272050135.html> , and I think he
has a point.

 _"The book is weird, uses antiquated technology, has horrible examples [...]_
"

Dive into Python has code examples which use ODBC:

 _"He has a [...] book that purports to teach people programming that still,
in 2010, references a piece of crap technology from the 90's. Yes, he actually
used that technology to teach Python in the beginning of his book six years
ago. [...]

Meanwhile, Mr. Pilgrim's book hasn't been updated in 6 years even though it's
[...] online and people can send him patches. [...]

Dive Into Python isn't just bad because of the use of ODBC, it's also just
full of bad initial examples. Take a look at your first Python program and
boggle at all the bizarre stuff a beginner has to suddenly comprehend:

\- A function, with a giant doc comment right away.

\- Weird underscore variables with a bad font making it look like one
underscore.

\- A list comprehension for-loop to join a string using a format string off a
tuple.

\- A dict, formatted with backslash chars that aren't even needed.

Holy crap, how in the hell is that a good first example? Even worse is it
starts a trend within the book of using ODBC as a theme to teach Python."_

Edit: Snipped strong language.

~~~
hackinthebochs
I disagree with Zed Shaw here. Ignoring the ODBC problem, Dive into Python is
written well for its target audience. This book is written for people who
already know how to program. Seeing a function with a doctstring, list
comprehensions, etc all at once is exactly the way I wanted to get a feel for
what python was about. It served its purpose very well. Now I will admit, some
of the examples did get tedious to the point where I skimmed them. But overall
the book served its purpose well.

------
fiore
Many of these are tutorials. You've asked for more of a reference. I've heard
people say that Beazley's Python Essential Reference is as close to a Python
K&R as there is, but I'm not experienced enough in Python to know.

~~~
Ratufa
Yes. Beazley's essential reference is the way to go. The docs at the Python
website are still essential for some things, though, since newer 2.X versions
of Python often have minor changes/additions from previous versions, such as
library changes and backports from Python 3.

------
gte910h
Python doesn't have one. It is too dynamic (especially compared to C), adding
new features year after year.

I'd say use the official docs combined with a cookbook or "learning python"
book (which is pretty big).

K&R got to be K&R because C really didn't change that much.

~~~
erez
I disagree, for instance, here's a (IMO) exact description of the K&R
'relevance':

"It's not even a very good way to learn C. The idioms and best-practices for C
programming have evolved substantially, even since the second edition was
published, and some of the code samples look a bit dated." And this is from
2004, meaning it got even more
dated.(<http://sites.google.com/site/steveyegge2/ten-great-books>)

The reason K&R is still the canonical C book is because it represents the
language better than any other book, before or since, not because the language
stagnated since ANSI C was created.

~~~
gte910h
K&R is the book people recommend because it WAS a great book for like 12
years. It just hasn't been since about 2002.

~~~
erez
That's true, but, IMO, there's a difference between learning to program in a
language and learning a language (aka "Thinking in X"). The K&R is still the
best source for the latter.

~~~
gte910h
I find that K&R uses some really stupid functions to do things, and as a
result causes many OTHER people do do some stupid things to do things.

I find that makes it wholly in adequate for thinking in C anymore. The "Never
trust data" mantra which is now part and parcel of C dev is not at all shown
in K&R.

------
jfxberns
I am surprised that O'Reilly's "Learning Python" hasn't received more nods.
Granted it's long (1200 pages as I recall), but it takes the reader on the
full journey through all of Python's multitude of features in a very
structured way, with each chapter building on the foundations the other
chapters lay.

I recommend "Dive Into Python" to people who want to start to get a taste of
Python, but anybody that has developed a appetite for Python and wants to
really, really Grok how Python works, I recommend O'Reilly's "Learning Python"
and tell them to take the time to read it cover-to-cover.

------
pillmuncher
I recommend The Python Cookbook: <http://oreilly.com/catalog/9780596001674>.
It's not a reference in the sense that it shows you the language syntax or
tells you the details of the standard library, but it shows how experienced
Pythonistas do things in a way that might not be obvious to you if you come
from a language like C or Java, or until you're Dutch.

------
serialx
Python in a Nutshell, O'Reilly Media, written by Alex Martelli
<http://oreilly.com/catalog/9780596100469/>

Definitely recommended for learning Python fast&practically. It's the most
comprehensive and useful Python reference book for programmers I've ever
encountered.

~~~
HedgeMage
Thanks for the recommendation, serialx; this (along with Essential Reference)
is contending to be my next purchase. :)

------
erez
I see, in this thread, a lot of good examples wrt good python books, but the
nature of the question left me to wonder. When I hear "What is the K&R of X",
it makes me think of "what is the book, preferably by the creator of the
language, that represent, most faithfully, the spirit of the language".

For example, compare Programming Perl (aka the Camel book) to K&R, the former
is a long, didactic, journey through Perl's linguistic building blocks, while
the latter is a laconic, technical, concise guide to C. I think these also
embody the philosophy and nature of these languages. Another example would be
Lisp/Scheme books that tend to be academic, and theoretical.

------
john2x
The official docs are great, but I personally find them difficult to navigate.

~~~
scott_s
I have found that Googling for "python docs _X_ " usually has the python doc
page for _X_ as the top hit.

------
espeed
Here is my list of recommended online Python tutorials, in order from
introductory to more advanced ([http://www.quora.com/How-can-I-learn-to-
program-in-Python/an...](http://www.quora.com/How-can-I-learn-to-program-in-
Python/answer/James-Thornton)). It also includes my dead-trees recommendation
-- "Python Cookbook," by Alex Martelli.

------
pbreit
The Python overview in the Web2py docs might be sufficient
(<http://web2py.com/book/default/chapter/02>). It's very concise but covers
the basics. Then, for reference, the Python docs are the way to go.

------
terinjokes
I feel horrible for derailing, but can I ask HN for a similar book for Ruby? I
know the basics of RoR, but feel like I would be a lot better if I knew more
about the Ruby underpinnings.

~~~
dimmuborgir
_The Ruby Programming Language_ by David Flanagan and Yukihiro Matsumoto (the
creator of Ruby) is very good.

The coverage, speed and size (half the size of Pickaxe book) make you
productive quickly.

~~~
cannedprimates
...and it's intentionally structured in a way that mirrors K&R!

------
richardhsu
"Python Pocket Reference, Fourth Edition"
(<http://oreilly.com/catalog/9780596158095/>)

------
djacobs
I used the Quick Python Book (Manning), which was perfect coming from Ruby. If
you're coming from anoth dynamic scripting language, I highly recommend it.

------
helwr
good thread here <http://www.quora.com/How-can-I-learn-to-program-in-Python>
and <http://news.ycombinator.com/item?id=2456994>

------
tretiy3
Python Cookbook is the best if you do not need to learn programming.

------
brudgers
"Monty"

If you were to find a K&R for Python, then it would be missing an important
something which is unique to Python - an acknowledgement and appreciation of
absurdity.

[edit: was "good humor"].

------
thdn
The Quick Python Book - Daryl D Harms Ph.D.

------
billiob
I like Learn Python The Hard Way by Zed Shaw:
<http://learnpythonthehardway.org/>

------
scscsc
Nothing.

