Python Coding Standards
Python Coding Standards
Tests – [/tests]: Just like documentation, tests also typically exist in most projects, and
should be placed in their own respective directory.
Code Structure
● Underscore
o between words also known as snake case -> ball_radius (Snake case is the practice
of writing compound words or phrases in which the elements are separated with one
underscore )
o at start (private/protected) -> _speed ( “_” is a simple convention at the start to
distinguish private and protected variables from the public ones )
● Uppercase for constants I.e. GRAVITY
Variable Access
● Avoid global variables unless it drastically simplifies code
○ If the variable is used throughout the entire program, global is probably fine
● Avoid public variables for classes. Enforce the idea of encapsulation
○ Instead of public variables, create getters and setters
Commenting
● Explain logic in a clear and understandable manner
● Keep them up to date
○ Outdated comments lead to more confusion
● Avoiding obvious comments
#print the age
print(age)
● When possible, rewrite the code so no comments are necessary
Logging in Lambda :
Log exception in your CloudWatch log Groups To output logs from your function code, you can
use any logging library such as logging that writes to stdout or stderr.