[Python] Calling functions from a dict, but with different params

Discussão em 'Python' iniciado por Stack, Julho 31, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I have this dictionary for action functions:

    def func1(param1, param2, param3):
    ...

    def func2(param2, param3):
    ...

    def func3():
    ...

    actions = {
    "case1": func1,
    "case2": func2,
    "case3": func3,
    ...
    }

    usecase = get_usecase()
    actions[usecase]() # this probably wouldn't work


    How to call the usecase functions which have different params, or doesn't have any param at all?

    Continue reading...

Compartilhe esta Página