I have a function func :
def func(a):
print a
func.__name_ = "My_Function"
To get the name of the function I will just do func.__name__.
But is there a way to call func() by using its name i.e. "My_Function"?
Edit: There are going to be large number of functions for which this has to be done. Is there any better solution apart from keeping a mapping of function.name to the function. ?
__name__is just a label, it's not the same as doingMy_Function = func.getattrto get function and invoke it. Have a look at this Question[f for _,f in locals().items() if callable(f) and f.__name__=='My_Function' ][0]('Hello'). Do try this at home, not in production. Use other option as Deepspace/johrsharpe suggested.