I want to fetch function with function name string eg.
class test(object):
def fetch_function():
print "Function is call"
#now i want to fetch function using string
"fetch_function()"
Result should be: Function is call
If you would leave the () from fetch_function() you could use getattr which is in my opinion safer than eval:
class Test(object):
def fetch_function():
print "Function is called"
test_instance = Test()
my_func = getattr(test_instance, 'fetch_function')
# now you can call my_func just like a regular function:
my_func()
eval("fetch_function()")It's not too safe tho, it opens a route for many hackers.