0

I have a class which gets a function as a parameter. I need to call a function then based on the previous function passed. Is there a way to do so?

For example, if myfunc() has been passed to the class, I need to call myfunc1() as it is the corresponding function(I already have the relationships between functions saved).

Hima Varsha
  • 261
  • 1
  • 13
  • there is a similar question [here](http://stackoverflow.com/questions/2654113/python-how-to-get-the-callers-method-name-in-the-called-method) getting caller method name in called method. – Kaladin Jul 01 '16 at 16:59
  • Can you include example code please? – Lost Jul 01 '16 at 17:03

1 Answers1

2

In order to get the name of a function, use __name__, e.g.:

def something(func):
    print(func.__name__)

def myfunc(): pass
something(myfunc) # prints 'myfunc'
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75