class MyClass:
def __init__(self, i):
self.i = i
def get(self):
func_name = 'function' + self.i
self.func_name() # <-- this does NOT work.
def function1(self):
pass # do something
def function2(self):
pass # do something
This gives the error: TypeError: 'str' object is not callable
How would I go about doing this?
Note: self.func_name
also does not work
self.func_name
you do not even access the local variablefunc_name
. You are trying to access an instance variable namedclass name
insideself
- but such variable does not exist. - Elazar