-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
  • 50,140
  • 28
  • 121
  • 140
tpayet
  • 42
  • 1
  • 5

2 Answers2

3

Sure, simply look into __name__:

>>> def foo(): pass
... 
>>> foo.__name__
'foo'
phihag
  • 278,196
  • 72
  • 453
  • 469
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,773
  • 6
  • 20
  • 32