0

I'm reading through a python class and confused with the following syntax:

handler = WorkerHandler()

handlers = {
    "create_vm": handler.create_vm,
    "add_guacamole_connections": handler.add_guacamole_connections,
    "delete_vm":handler.delete_vm
}

I know that this is creating a dictionary but I'm just confused as to what this dot notation is called in python. I tried looking up "reference to function" but this does not work

questions
  • 473
  • 6
  • 19
  • 1
    Those are [function objects](https://stackoverflow.com/questions/25292239/are-functions-objects-in-python) that you can call at a later time. Specifically those are [bound class methods](https://stackoverflow.com/questions/114214/class-method-differences-in-python-bound-unbound-and-static) – Cory Kramer May 19 '21 at 18:55
  • those are methods of a class, so if you do `handlers["create_vm"]()` it will call the `handler.create_vm` function – gold_cy May 19 '21 at 18:55
  • You don't actually need such a `dict`, since all your keys match the desired method name. `operator.methodcaller("create_vm")(handler) == handler.create_vm()`. – chepner May 19 '21 at 19:01

0 Answers0