đĻ Hey want tO see a nEat PYtHoN triCK?
def f(name: str):
print("hiya {}".format(name))
locals()["f"]("Spongebob")
đŽ Oh cool, does that use the string "f"
to find--
đĻ DoEs It FiNd ThE fUnCtIoN "f"
aNd CaLl iT?? yEaH It DoEs.
$ python script.py
hiya Spongebob
đŽ Oh that's neat. I didn't know you could do that with Python--
đĻ whaTEveR i dON't cArE wHaT YOU tHinK.
đŽ You asked me --
đĻ I sAiD sHuT uP. i'M dOiNg HoT gIrL sHiT.
đŽ Are you ok? You're yelling a lot about Python again--
# shut up
def test_patrick(context: TestContext):
# do thing
def test_crabs(context: TestContext):
# do other thing
context = TestContext()
tests = []
for t in locals():
if t.startswith("test_"):
tests.append(t)
for test in tests:
test(context)
đŽ Oh so you could...
đĻ ...
đŽ Are you going to interrupt me?
đĻ Not yet.
đŽ Ok... you could search your scope and find a bunch of functions with a name and common interface--
đĻ AND CALL THEM! DYNAMIC DISPATCH!!
đŽ That's nice.
đĻ YEAH IT IS COOL!