Python quick note

Anh-Thi Dinh
draft
⚠️
This is a quick & dirty draft, for me only!
Flask vs fastapi : r/flask , django for building web apps.
  • Flask is easier than FastAPI. Flask is “do whatever you want”, good when you need both back and front into one package.
  • as things get bigger, with more endpoints, more base routes (the http://website.com/<ROUTE>/other/stuff part), FastAPI has made my life quite nice.
  • FastAPI so when speed is important as well as organization, models, validation, and you do want things like async
different parts of your program run concurrently and can simplify your design
1import threading
2x = threading.Thread(target=thread_function, args=(1,))
3x.start()
  • Most Python 3 implementations the different threads do not actually execute at the same time: they merely appear to
  • Tasks that spend much of their time waiting for external events are generally good candidates for threading.
  • If you define a new funciton and wait for it plementation, just use pass as its content.
1def somefunction():
2	pass
Using d.get("prop", default_value) for dictionary in Python. .get() always returns a value whereas d["prop"] will raise a KeyError if the given key is missing.