Style Guide for Python Code - Summary
From Julian Yap
- Module names should be in all lowercase - hello.py.
- Class names should be in CamelCase.
- Methods and functions should be in lower_with_underscores
- Implementation-specific 'private' methods _single_underscore_prefix
- Especially private non-subclassable methods __double_underscore_prefix
- Top level constants (i.e. those that are not in a function or class) should be in BLOCKCAPITALS. Overuse of these constants may make your code less reusable.
- If a variable inside a function or method is so temporary and disposable that you cannot give it a name, then use i for the first one, j for the second and k for third.
- Indentation is four spaces per level. No tabs. If you break this rule then you must be stoned in the village square.
- Lines are never more that 80 characters wide. Tip, break lines with a backward slash \. You do not need to do this if there are parentheses, brackets or braces. Don't add extra parentheses just to break lines, use \ instead.
- Spaces after commas, (green, eggs, and, ham)
- Spaces around operators i = i + 1
- Write docstrings for all public modules, functions, classes, and methods. Python is an international community, so use English for docstrings, object names and comments. If you want to provide local translations then use a proper localisation library.
From: http://commandline.org.uk/python/twelve-commandments-of-python-style-2008-04-25-19-00.html
