-2

I have a script which monitor a directory and call a function with certain arguments. And in this script a open file.log to explain what happened each time there is a new file in the monitored directory.

This is the prototype of my function :

def and_now_my_watch_begin(dir_to_watch, function_to_call, *args_for_function):

I would like to know if there was any way to get function's name like a function.name.to_str() or something like this ?

Bhargav Rao
  • 45,811
  • 27
  • 120
  • 136
tpayet
  • 42
  • 1
  • 5

2 Answers2

3

Sure, simply look into __name__:

>>> def foo(): pass
... 
>>> foo.__name__
'foo'
phihag
  • 263,143
  • 67
  • 432
  • 458
0

You can use the __name__ attribute of the function. For example:

def function():
    return

print(function.__name__)

This will print:

'function'
Rob Murray
  • 1,647
  • 6
  • 19
  • 30