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

3
  • 1
    Those are function objects that you can call at a later time. Specifically those are bound class methods Commented May 19, 2021 at 18:55
  • those are methods of a class, so if you do handlers["create_vm"]() it will call the handler.create_vm function Commented May 19, 2021 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(). Commented May 19, 2021 at 19:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.