Skip to content

Python coding convention

1337 edited this page Aug 16, 2012 · 4 revisions

tl;dr

Line Length

Strictly less than or equal to 79 characters, unless any of these applies:

  • it is impossible to break the line up to below 79 characters
  • it looks uglier than before you trim it down to 79 characters
  • line length includes spaces.

Tabs and spaces

  • no tab characters of any kind shall be found in our code.
  • no trailing spaces of any kind shall be found in our code.
  • indentation: 4 hard spaces.

Class Names

  • CamelCase

Property Names

  • prop_name

Variable Names

  • var_name
  • at least three meaningful characters, unless it is a variable used for looping, itself unused in the loop. In which case, use _.

Docstrings / Comments

  • use PEP 257.
  • docstrings must be meaningful.
  • there is (hardly ever) too many comments - as long as they are meaningful, updated, and don't repeat themselves

Trailing commas

Always for dictionaries, and never for tuples

Clone this wiki locally