I've been using Python since version 2.2. I do pick up new language constructs like for example with statement or dictionary/set comprehensions. However, I've realized that even though I'm being consistent with PEP-8, for existing constructs I'm using old style, rather than new style (for example except Exception, e instead of except Exception as e).

Is there a resource which would have either most current style guide, or even better a list of changes in Python's coding style?

  • The only way to be completely up-to-date with coding styles is to read lots of up-to-date source code. For example, knowing the intent of new syntax is great, but there are usually surprise interactions with old syntax that can lead to surprising new style conventions. So watch what people are doing, look for creative ideas, look for praise and criticism and in the end judge for yourself what works - but of course be conservative about how much you use in real projects. One or two new style ideas may benefit a project, but too many will make things unreadable. – Steve314 Aug 25 '13 at 15:15

I'd look through the What's new documentation; whenever new syntax has been introduced it is invariably an improvement over the old.

Each What's New document (one per minor version, so for 2.5, 2.6, etc.) starts by summarising the Python Enhancement Proposals (PEP) that made it to that release. New syntax, functions and modules that you want to know about are invariably listed as a PEP.

The next documents you can look for is to search for blog posts, presentations and articles about "Idiomatic Python"; these usually try to teach you good, often newer, python style:

Last but not least, try answering questions on Stack Overflow on the python tag; any style mistakes you make will be swiftly pointed out to you. It is a very swift path to discovering what better style is availabe. :-)

  • +1 for the effort, but unfortunately that's not really the answer: "Code Like a Pythonista" is from 2007, other two are newer, but quite basic and don't mention my example (Exceptions), and for [python] on SO, I think I've got quite a few. Good point on What's New, but that's mostly about features, not style. – vartec Jun 28 '13 at 9:59
  • @vartec: The Code Like a Pythonista document has been updated since that first post date. – Martijn Pieters Jun 28 '13 at 10:04
  • @vartec: The new features dictate new style. People switched to except Exception as e because it became available, described in a What's new document. – Martijn Pieters Jun 28 '13 at 10:06
  • Fair enough, I see your point. Though I'd love something more concise, focusing on the style only. As for CLaP, it's seems to have been updated in 2008, original version being from 2006, lacks all the new stuff of 2.6 & 2.7, not to mention 3.x; – vartec Jun 28 '13 at 10:10
  • I got some mileage out of it in any case, pointing to some of the entries from SO answers. – Martijn Pieters Jun 28 '13 at 10:13

If you are ready to move to Python 3.x, read Python Cookbook, 3rd Edition, by David Beazley and Brian K. Jones. By solving many practical problems in different areas it showcases a modern style of programming in which takes advantage of the newest language features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.