Create a dict of functions that you want to call using a string:
def test(test_config):
for i in test_config:
print i.header //prints func1
print type(i.header)
try:
methods[i.header]()
except (AttributeError, TypeError):
logging.error("Method %s not implemented"%(i.header))
def func1():
print "In func1"
def func2():
print "In func2"
methods = {u'func1':func1, u'func2':func2} #Methods that you want to call
Using class:
class A:
def test(self, test_config):
try:
getattr(self, i.header)()
except AttributeError:
logging.error("Method %s not implemented"%(i.header))
def func1(self):
print "In func1"
x = A()
x.test(pass_something_here)