0 votes
1 view
in Python by (47.8k points)

In Python, how do I get a function name as a string, without calling the function?

def my_function(): 

pass print 

get_function_name_as_string(my_function) # my_function is not in quotes

should output "my_function".

Is such a function available in Python? If not, any ideas on how to implement get_function_name_as_string, in Python?

1 Answer

0 votes
by (107k points)
  • In Python, every function has a property called ‘.__name__’ attached to it. We can access this property and get the name of a function. 

  • For example:

def abc_func():

    return 0

print (abc_func.__name__)

image

 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...