mardi 6 juin 2017

Calling functions based on received data [duplicate]

This question already has an answer here:

How could I reduce many "if" in my code?

For example:

example = "smth"
if example == "smth":
   foo1()
elif example == "smth2":
   foo2()

Is any other way to call object / function based on received data?

Example:

I recive "foo" - call function foo

I recive "calculate" - call function calculate

My lecturer suggested that I should create "dispatcher" but I don't know how

Aucun commentaire:

Enregistrer un commentaire