Python style guide - mikec964/chelmbigstock GitHub Wiki

Most of this is from PEP-8

Formatting

  • Indent using four spaces

  • You can use extra indents to align arguments; then no arguments on 1st line

    Aligned with opening delimiter

    foo = long_function_name(var_one, var_two, var_three, var_four)

    More indentation included to distinguish this from the rest.

    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

Code style

  • 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 *

Naming

  • 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

Other

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.

⚠️ **GitHub.com Fallback** ⚠️