0

I have these methods in a class "driver":

  • def act_left()
  • def act_right()
  • def act_straight()

When I call for init of that class I get an array of actions numbers between 0-2 and I translate these into the actions above. I thought about using switch-case but I found out there is no such thing in python 3.9. Do you know any elegant alternative, since I really has 10 of these actions and don't want to do a lot of else if's.

Thanks!

John
  • 17
  • 3
  • No since I need to activate a function in my object. – John Aug 09 '22 at 21:16
  • Maybe a list of functions: `actions = [act_left, act_right, act_straight]`. Then `for i in list_of_numbers: actions[i]()`. – 001 Aug 09 '22 at 21:17
  • Why can't you use a dictionary to replace a switch statement and still activate a function in your object? – mkrieger1 Aug 09 '22 at 21:25

0 Answers0