2

I apologize if my terminology is incorrect. I am trying to get the name of the function from an API return. For example, the following is what is returned from an API. How do I get the name, the_function?

my_variable = <Function the_function(str,int,uint)>

The type of the above is:

type(my_variable) = <class 'the_class.utils.datatypes.the_function'>

If I only have access to what I have shown, how to I the text string the_function? Is there an easy way to do it besides turning it into a string and using regex or something similar?

khelwood
  • 52,115
  • 13
  • 74
  • 94

2 Answers2

1

Use __name__ argument:

def yourfunction():
    pass

print(yourfunction.__name__)

Then now you'll get expected output.

U12-Forward
  • 65,118
  • 12
  • 70
  • 89
1

If you have access to that function through literally any variable, you can use .__name__:

 >>> def the_function():
...     pass
... 
>>> the_function.__name__
'the_function'
>>> foo = the_function
>>> foo.__name__
'the_function'
Ayxan Haqverdili
  • 23,309
  • 5
  • 37
  • 74