Python style guide - mikec964/chelmbigstock GitHub Wiki
Most of this is from PEP-8
-
Indent using four spaces
-
You can use extra indents to align arguments; then no arguments on 1st line
foo = long_function_name(var_one, var_two, var_three, var_four)
def long_function_name( var_one, var_two, var_three, var_four): print(var_one)
-
2 blank lines before top-level function and class definitions
-
UTF-8
-
Space around assignment and comparison operators
-
No space on argument default assignment
-
Docstrings should end with triple double quote on a line by itself
-
See PEP 257 for docstring conventions
- Imports at top of file: standard, then related, then local. Separate by groups by blank lines.
- Imports on separate lines
- Avoid wildcard imports; no
from XX import *
- Package and module names: short_underscores
- Class names: CapWords
- Exception names: CapWordError (suffix with Error)
- Function names: the_date
- Private methods: _the_date
- Constants: ALL_CAPS
You can run your program with python <filename.py>
. Use python -i <filename.py>
to run the program and then return to the interactive Python prompt.
To run your program just by typing the name, put this line at the top of the main program: #!/usr/bin/env python
or #!/usr/bin/env python3
, and then set the file permissions to be executable with chmod u+x <filename>.py
(for the user) or chmod +x <filename>.py
for all.