I would like to use functions based on strings passed in argument as below. The code gives the following error: AttributeError: 'Obj' object has no attribute 'funA'
The functions funA and funB are defined within fun because they are only used within fun and nowhere else
class Obj(object):
def __init__(self):
self.A = 2
self.B = 3
def fun(self, ar):
def funA(self):
print self.A
def funB(self):
x = self.B + 4
print self.B
for letter in ar:
name = 'fun' + letter
getattr(self, name)()
obj_instance = Obj()
obj_instance.fun(['A', 'B'])
self(the Obj instance), but local variables insidefun.