I have many different methods in a class. Each method contains a function for a unique case. The case is passed to the constructor as a simple integer that identifies which method should be used. Is there a better way to set call this function then just a bunch of if statements?
class Class:
def __init__(self, case):
self.__case = case # case is a integer from 1 to 10
if case == 1:
self.case1()
elif case == 2:
self.case2()
elif case == 3:
self.case3()
...
elif case == 10:
self.case10():
def case1(self):
...
def case2(self):
...
def case10(self):
The code works but it is very redundant. Is there a more pythonic way of doing this?