Best Practices (Python)

Check if dictionary contains key, if not return default value

# not so good
if 'owner' in roledict:
    owner = roledict['owner']
else:
    owner = admin
 
# just slightly better, still not good
try:
    owner = roledict['owner']
except KeyError:
    owner = admin
 
# better
owner = roledict.get('owner', admin)

Invoking subprocesses

In order to spawn new processes like you would do in a shell, use the subprocess module of the Python standard library. It should be used instead of the os.system module.

Object Oriented Programming

SOLID design princibles: https://www.youtube.com/watch?v=pTB30aXS77U

  • Single responsibility
  • Open/Closed
  • Liskov substitution
  • Interface segregation
  • Dependency inversion
Log In