Python: PEP 8 Brush Up

Keeping with my recent optimizations, I did a little brushing up on PEP 8 - Python's Style Guide. Here's a short list of some things I need to pay more attention to:
  1. Limit all lines to a maximum of 79 characters, 72 for flowing long blocks of text.
  2. Wrap single spaces around binary and arithmetic operators.
  3. Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.
  4. "from x import *" does not import _single_underscore_names (weak internal).
  5. single_trailing_underscores_ can be used to avoid conflicts with Python keywords.
  6. Never use the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), or 'I' (uppercase letter eye) as single character variable names.
  7. Class names and exceptions use the CapWords naming convention.
  8. Exceptions that are errors should use the suffix "Error."
  9. function_names should be lowercase, words separated by underscores as necessary.
  10. Constants are usually declared on a module level and written in all capital letters with underscores separating words.
  11. Use ''.startswith() and ''.endswith() to check for prefixes or suffixes.
  12. Always use isinstance(obj, (int, str, dict, etc...)) instead of comparing types directly.

Comments

    Post a Comment