python_tips
latest

Contents:

  • Boolean
  • Class
  • Decorator
  • Exception
  • Function
  • Import
  • Set
  • Security
  • Lambda
  • List
  • Loop
  • None
  • PEP8
  • Performance
  • With
python_tips
  • Docs »
  • Welcome to python_tips’s documentation!
  • Edit on GitHub

Welcome to python_tips’s documentation!¶

Document the best practice in python that may be used during development.

Contents:

  • Boolean
  • Class
    • 1. Don’t access the private attributes from outside.
    • 2. __init__ do not use return statement.
    • 3. Do not dynamically creating variable.
  • Decorator
  • Exception
    • 1. subclass of Exception need to place before parent Exception class
    • 2. Secure your exception
  • Function
    • 1. Do not use mutable objects as an argument
    • 2. Do not return more than one variable type from function call.
    • 3. Do not use global statement.
    • 4. Return more than one result using nameturple.
  • Import
    • 1. Don’t import module using *
  • Set
  • Security
    • 1. avoid the exec function.
  • Lambda
    • 1. Don’t use lambda with anonymously.
  • List
    • 1. unpack the variable in list using explicit unpacking.
    • 2. Using zip() to iterate over a pair of lists.
    • 3. Use list comprehension instead of map().
    • 4. Check for the empty list.
    • 5. initialization on list.
  • Loop
    • 1. else clause of the loop
    • 2. Use enumerate instead of len to access each element.
  • None
  • PEP8
    • 1. Python code indented with 4 spaces.
    • 2. None Compare.
    • 3. boolean Compare.
    • 4. Type comparison.
    • 5. Only use the is operator to check the exact identity of two references.
    • 6. Duck Type
  • Performance
    • 1. Don’t check if key in list.
    • 2. Use iteritems() to iterate over large dictionary.
    • 3. String Concatenation.
  • With
    • 1. open file with with keyword to prevent memory issues.

Indices and tables¶

  • Index
  • Module Index
  • Search Page
Next

© Copyright 2020, JunWei Song Revision 5fc87324.

Built with Sphinx using a theme provided by Read the Docs.