You can use __name__
attribute to get your function name :
Example :
>>> def my_func():
... print 'my_func'
...
>>> my_func.__name__
'my_func'
Read more about python modules https://docs.python.org/2/tutorial/modules.html#modules
Also note that since you have called your function within functions_results
:
functions_results = [
schedules(),
^ #here you called the function
schedules("2014-06-01", "2015-03-01"),
]
So you can not get its name in your loop. for example if in preceding example we want to get the name of function after call python will raise an AttributeError
:
>>> my_func().__name__
my_func
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute '__name__'
>>>
So for getting ride of this problem you need to put the function without calling it in your list :
functions_results = [
schedules,
schedules("2014-06-01", "2015-03-01"),
]
Also note that you can not do it again for second function call :
schedules("2014-06-01", "2015-03-01")
and for getting ride of this problem too you can use hasattr(obj, '__call__')
method (and callable
in python3 )to check if i
was a function type then get its name :
for i in list_of_functions_heads:
if hasattr(i, '__call__'):
print i.__name__