Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中获取指向当前函数的指针?_Python_Function - Fatal编程技术网

如何在python中获取指向当前函数的指针?

如何在python中获取指向当前函数的指针?,python,function,Python,Function,可能重复: 是否有一种方便的方法来获取当前函数的指针 例如: current_func_ref = None def func(): current_func_ref = ___ #something need to fill do something.. 好吧,这有点厚颜无耻,不像你可能想要的那么普通,但不管怎样,这里是: current_func_ref = None def func(): global current_func_ref current_

可能重复:

是否有一种方便的方法来获取当前函数的指针

例如:

current_func_ref = None
def func():
    current_func_ref = ___ #something need to fill
    do something..

好吧,这有点厚颜无耻,不像你可能想要的那么普通,但不管怎样,这里是:

current_func_ref = None
def func():
    global current_func_ref
    current_func_ref = func

您想要对堆栈上正在调用的当前函数进行引用吗?您最后想做什么?这对于Python来说是一种非常奇怪的模式。注意:
current\u func\u ref
函数内部创建了一个本地名称。它对外部级别的当前函数没有影响。当您更改函数名时,您还需要更改代码。@user1544915是的,因此我将其描述为厚颜无耻且非泛型。但正如其他评论者所说,即使一开始就想这样做也很奇怪。你到底想解决什么问题?