7 ms·
Ask HN: ______ is to Python as K&R is to C?
I'm in need of a book recommendation for learning Python (not learning programming, just adding this language to my repertoire).
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 reference 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.
Basically, my ideal programming book is Kernighan and Ritchie's "The C Programming Language" -- I want that, but for Python.
- ScottBev 15y agoI end up going back to "Dive Into Python" for reference. http://diveintopython.org/ http://diveintopython.org/ My other two references are the Python Standard Library Docs (http://docs.python.org/library/index.html http://docs.python.org/library/index.html) and StackOverflow.
- arasraj 15y agoDive 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 15y agoZed Shaw disagrees: http://oppugn.us/posts/1272050135.html 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 15y agoI 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.
- deleted 15y ago[deleted]
- john2x 15y agoThe official docs are great, but I personally find them difficult to navigate.
- scott_s 15y agoI have found that Googling for "python docs X" usually has the python doc page for X as the top hit.
- deleted 15y ago[deleted]
- imurray 15y agoThat page says "If you can already code then the book will probably drive you insane", which doesn't match the poster's request. (The parent, now deleted, was referring to http://learnpythonthehardway.org/ http://learnpythonthehardway.org/ which a couple of other posters also link to.)
- billiob 15y agoI like Learn Python The Hard Way by Zed Shaw: http://learnpythonthehardway.org/ http://learnpythonthehardway.org/
- thirsteh 15y agoThe official Python, http://docs.python.org/tutorial/ 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 http://learnpythonthehardway.org/index * How to Think Like a Computer Scientist/Think Python (now Python for Software Development) -- http://www.greenteapress.com/thinkpython/ 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 15y agoIf you know how to program allready I really don't recommend 'Learn Python The Hardway'... it might bore you.
- kbob 15y agoLike K&R, the official docs were written by the language designers/implementors. I think that's important: it eliminates a level of misunderstanding (between the designers and the writers).
- terinjokes 15y agoI 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.
- r00k 15y agoProgramming Ruby (aka "the Pickaxe"). I never fully grokked Ruby's object model until I read that book. I reread it often and always discover/re-discover useful information.
- dimmuborgir 15y agoThe 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 15y ago...and it's intentionally structured in a way that mirrors K&R!
- djacobs 15y agoI've read many Ruby books over 6 years. The best, in my opinion, is David Black's "The Well-Grounded Rubyist". I read it just last year as an experienced Rubyist. I thought it had a fantastic, no-magic take on the language that offered a better perspective on scope, metaprogramming, and general language design than any other book I've read. That said, I haven't read the Matz book.
- fiore 15y agoMany 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.
- gmantastic 15y agoYes, Python Essential Reference by David M. Beazley is great. If you already know how to program, this is the one to buy and keep on your desk.
- samuel 15y agoI agree. I think it's a great choice for experienced programmers: concise and to the point and exhaustive.
- Ratufa 15y agoYes. 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.
- pillmuncher 15y agoI recommend The Python Cookbook: http://oreilly.com/catalog/9780596001674 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.
- angrycoder 15y agoAll 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 15y agoWhy, 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?
- HedgeMage 15y agoObviously, I want one, or I wouldn't have asked!
- angrycoder 15y agoThe back of the book is not just a copy and pasted version of the standard python docs, it is more of an annotated reference. People pay money for this stuff because they either want a different viewpoint or more indepth coverage on certain topics.
- wcarss 15y agoI got Ruby Best Practices and the Pragmatic Bookshelf's 'Programming Ruby 1.9' from the library last summer, and had an incredibly productive time. I would sit in front of my laptop reading RBP, and any time I was confused by a class or anything, flip there in the reference and see what the method did. I could keep my terminal up on screen and not switch into "web browser + search engine" mode at all. Having a book is like having an additional monitor full of information that is uncompromising on your task. It's also wonderful to read, and easy to pop open even when your laptop isn't out, and you're just curious "I wonder if Array has a method to do ...." A final note, because of that, having a paper reference (especially an annotated one) lends itself strongly to actually reading large swaths of it, instead of just finding the method you need and putting it away. With it being clunky, you don't want to do a lookup twice, so you open it and keep it open, and often read through a module/class' entire method list. That really improves your knowledge. So in short, because it encourages good work and work practices.
- brudgers 15y ago"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"].
- espeed 15y agoHere 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/answer/James-Thornton http://www.quora.com/How-can-I-learn-to-program-in-Python/an...). It also includes my dead-trees recommendation -- "Python Cookbook," by Alex Martelli.
- richardhsu 15y ago"Python Pocket Reference, Fourth Edition" (http://oreilly.com/catalog/9780596158095/ http://oreilly.com/catalog/9780596158095/)
- gte910h 15y agoPython 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.
- HedgeMage 15y agoUpvoted for the insight on why I'm having trouble finding a K&R equivalent for Python. I bought "Learning Python" because it covers both 2.x and 3.x, but found it absolutely unnavigable as a reference. It might work well for people who want a tutorial they can go through step by step, but for someone who just wants to quickly find and absorb info in the process of doing something else, it doesn't cut the mustard.
- erez 15y agoI 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 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 15y agoK&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 15y agoThat'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.
- serialx 15y agoPython in a Nutshell, O'Reilly Media, written by Alex Martelli http://oreilly.com/catalog/9780596100469/ 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 15y agoThanks for the recommendation, serialx; this (along with Essential Reference) is contending to be my next purchase. :)
- helwr 15y agogood thread here http://www.quora.com/How-can-I-learn-to-program-in-Python http://www.quora.com/How-can-I-learn-to-program-in-Python and http://news.ycombinator.com/item?id=2456994 http://news.ycombinator.com/item?id=2456994
- djacobs 15y agoI 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.
- tretiy3 15y agoPython Cookbook is the best if you do not need to learn programming.
- pbreit 15y agoThe Python overview in the Web2py docs might be sufficient (http://web2py.com/book/default/chapter/02 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.
- scscsc 15y agoNothing.
- erez 15y agoI 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.
- thdn 15y agoThe Quick Python Book - Daryl D Harms Ph.D.
- jfxberns 15y agoI 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.