可能重复:
How to get the function name as string in Python?如何在Python中获取函数名称作为字符串?
我知道我能做到这一点:
def func_name():
print func_name.__name__
这将返回的功能为 'my_func,并将' 的名称。
但是,当我进入函数,有没有办法直接调用它的一般? 喜欢的东西:
def func_name():
print self.__name__
在它是由Python会明白,我想我的代码层次上的?
顺便说一句,'self'是不是魔术关键字Python,它只是一个约定,用于命名传递给实例方法的第一个参数(这是该方法所绑定的实例)。 – geoffspear
我不认为有任何简单的解决方案。检查这个问题http://stackoverflow.com/questions/5063607/is-there-a-self-flag-can-reference-python-function-inside-itself – rplnt
你打算用什么名字? –