4 ms·
Ask HN: What's the best source to learn idomatic Python?
Long story short, I'm coming from 15 years of Perl but now trying to pick up Python. I want to do it the right may (best practices) rather than hack my way in, so was wanting the best (and up-to-date) guide on idiomatic Python.
Any suggestions?
- sndean 9y agoI went through "Fluent Python: Clear, Concise, and Effective Programming" and think it's probably the best Python (or any programming language?) book I've tried. Not sure if a book is what you meant by guide.
- alfiedotwtf 9y agoYep, I've been on Amazon for the past hour, and this looks good. Thanks!
- mayankkaizen 9y agoFluent Python is the best intermediate level Python book I have read. It is one book you wish to have more and more pages.
- alfiedotwtf 9y agoThanks for the confirmation :) Added to my shopping list!
- clusmore 9y agoCheck out Raymond Hettinger's talks on YouTube. Here's one to get you started: https://youtu.be/OSGv2VnC0go https://youtu.be/OSGv2VnC0go
- alfiedotwtf 9y agoThanks, adding to my watch list!
- vram22 9y agoAnother good Python video is Ned Batchelder's "Loop like a Native". Has lots of examples of non-idiomatic vs. idiomatic ways of looping in Python. Google a bit before reading, there may be more than one video, or a blog post and a video. Check for the latest one etc.
- codegladiator 9y agohttps://www.learnpythonthehardway.org/ https://www.learnpythonthehardway.org/
- alfiedotwtf 9y agoOoh. I don't know if I have the time
- mjhea0 9y agohttps://jeffknupp.com/writing-idiomatic-python-ebook/ https://jeffknupp.com/writing-idiomatic-python-ebook/
- alfiedotwtf 9y agoPurchased. Thanks!
- Jugurtha 9y agoThe Python documentation is pretty cool. I frequently go to Chapter 3 (Data Model) and always learn something new reading something I had already read but didn't quite get. The mailing list has top notch posters who are always willing to help. The IRC channel (#python) has very helpful members who've been patient with me on more than one occasion. Books: Stacking the deck: "Python Guide" - Kenneth Reitz: The bits one doesn't necessarily think about but that simplify life: virtual environments, unit test, project structure, good practices, scenarios for different kinds of applications, documentation, etc. Doing stuff: "Python Cookbook" (several editions by different authors, Alex Martelli and David Beazley): as the title states, it's a cookbook that shows you how to do a bunch of stuff in Python (files, network, threads, etc). This can get you "operational" in Python pretty fast. Doing stuff well (meta): "Writing Idiomatic Python" - Jeff Knupp: The book comes for Python 2 and Python 3 and contrasts "harmful" and "good". Jeff Knupp also has videos showing you the process of refactoring code. He also has a blog (https://jeffknupp.com/ https://jeffknupp.com/) where he addresses many topics. "Effective Python: 59 Specific Ways to Write Better Python" - Brett Slatkin: Pretty good book. The subtitle says it all: 59 specific ways to write better Python. (600 + pages). "Learn Python the Hard Way" - Zed Shaw: I've read that starting out in Python. Maybe not for a 15 year Perl veteran, but this is for memo. There's certainly some overlap in these books, but it helps to repeat a message to understand the importance of something, or to drive a point home. I didn't use virtual environments until the message was repeated enough in different ways. Pornography: PyCon talks. A lot of these are great. David Beazley (a bunch of talks that are pretty cool. Still haven't finished the ones on generators but they're very good). Brandon Rhodes (on aesthetics and design patterns (or lack thereof), and testing web applications). Kenneth Reitz on design. Raymond Hettinger (you'll find "Writing Beautiful Idiomatic Python" and "Beyond PEP8" most helpful).
- saamm 9y agoSeconding the recommendation on Chapter 3! Well-defined special/dunder/magic methods can make your code way more readable.
- vram22 9y agoSeconding the recommendation for the Python Cookbooks (by O'Reilly). I have both the Py 2 and Py 3 versions. I've read the 2 book (multiple authors) pretty much fully (and much of it more than once), except for a few more advanced recipes, or areas that I was not that interested in, and found it really good. Used some of the ideas and techniques in some production code. The chapter in it on iterators and generators is particularly good (some of the stuff in it is by Raymond Hettinger, who also, IIRC, designed and implemented much of the iterator and generator functionality in Python 2). I've only read parts of my copy of 3 so far, but it is good too, though the style is somewhat different. It is more brief (per recipe, though the book overall is as large or larger than 2), and you have to do more work yourself to understand the recipes. The authors explicitly say this.
- amirouche 9y agoLook up interview questions on the web, I find them very useful to get an idea of what makes good python programming. I have none to recommend in particular.
- alfiedotwtf 9y agoDidn't think of that. Out of the box... nice
- vram22 9y agoIt is probably somewhat out of date now (w.r.t. to new language and library features of Python), but David Goodger's site also has a list of idiomatic Python topics; had read it a while ago. This is it: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html http://python.net/~goodger/projects/pycon/2007/idiomatic/han...
- alfiedotwtf 9y agoYep, that was one of the first things I found. Will be going through this ASAP