Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a nice "python conventions and best practices" summary anywhere?

I am fairly new to python, and I generally code as a means to an end, as opposed to being a "coder". I like all the power that python contains through libraries, and I enjoy the inherent but invisible strength in python. (E.g., object-oriented, but still relatively scripter-friendly structure for making classes, etc.)

But I keep running into cases where I cannot find complete documentation, and I find pointers to the appropriate documentation only after discovering the problem I have accidentally created. So far, I have only found references to the following appropriate documentation:

PEP 0008
PEP 0257

Unless I missed something, however, neither of these captured issues regarding "proper" python file naming conventions. After making several python scripts, I discovered that I am not supposed to use periods ( . ) in the file name, since it will make it a challenge to import them. After running into this problem, I could indeed find links talking to this point:

no periods allowed

However, I'd really like to start tackling issues pro-actively, instead of having to step backwards through the proper mechanisms. Python has SEVERAL aspects which make it quite unique (such as required whitespace & the aforementioned disallowed periods in filenames). I am too new to say whether these are good things or bad things. But I can say that it is a pain to keep discovering all these things after the fact.

Is there any sort of "encyclopedia" which may capture all these idiosyncrasies, beyond the 2 relatively brief documents I've cited above?

Thanks, all!
Mike

like image 727
Mike Williamson Avatar asked Apr 12 '11 21:04

Mike Williamson


2 Answers

I don't know of any definitive source that covers everything but in addition to the links you already posted you should definitely check these links out for some best practices:

  • Google Python Style Guide
  • PythonStyleGuide

These cover style and also highlight some gotchas that can be avoided by using certain conventions and patterns.

like image 195
Andrew Hare Avatar answered Nov 08 '22 18:11

Andrew Hare


I really like Code Like a Pythonista: Idiomatic Python article by David Goodger.

like image 21
Pekka Klärck Avatar answered Nov 08 '22 20:11

Pekka Klärck