获取函数名称到字符串

时间:2015-12-10 10:23:03

标签: python python-3.x

我有一个监视目录并使用某些参数调用函数的脚本。并在此脚本中打开一个file.log来解释每次监视目录中有新文件时发生的情况。

这是我的功能原型:

def and_now_my_watch_begin(dir_to_watch, function_to_call, *args_for_function):

我想知道是否有办法让函数的名称像function.name.to_str()或类似的东西?

2 个答案:

答案 0 :(得分:3)

当然,只需查看anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)             anView!.canShowCallout = true             anView!.animatesDrop = true

__name__

答案 1 :(得分:0)

您可以使用该函数的__name__属性。例如:

def function():
    return

print(function.__name__)

这将打印:

'function'