-2

As soon as i define this dictionary:

case_dict={
    "run" : runn(),
    "name" : namee(),
    "help" : helpp(),
    "quit": quitt(),
}

python runs all these functions successively. How do i avoid these functions from running in the console when i just want to define the dict ?

PS: all these functions are defined earlier in the code.

bendo97
  • 21
  • 6

1 Answers1

3

You assigned the value of each key to the return value of the function, not the function itself. Through the brackets at the end the functions get executed the moment you create the dict.

to avoid this, write runn instead of runn()

so you would end up with

case_dict={
    "run" : runn,
    "name" : namee,
    "help" : helpp,
    "quit": quitt,
}

Now, if you would like to call one of these functions you would do it like so:

case_dict["run"](parameter_1, parameter_2 ... )
SyntaxError
  • 330
  • 3
  • 16