问题描述
请看下面的代码:
#mystringfunctions.py
def cap(s):
print s
print"此功能的名称是 +" ???"
cap(" hello")
运行上面的代码会给出以下输出
这可能吗?
这可能吗?
是的,使用模数检查来访问当前的堆栈框架:
def handle_stackframe_without_leak():
frame = inspect.currentframe()
尝试:
打印inspect.getframeinfo(框架)[2]
终于:
del frame
Diez
这可能吗?
是的,使用模数检查来访问当前的堆栈框架:
def handle_stackframe_without_leak():
frame = inspect.currentframe()
尝试:
打印inspect.getframeinfo(框架)[2]
终于:
del frame
Diez
sys._getframe()会帮助你:
函数名是上限
-Peter
Look at the code below:
# mystringfunctions.py
def cap(s):
print s
print "the name of this function is " + "???"
cap ("hello")
Running the code above gives the following output
Is that possible ?
Is that possible ?
Yes, use the moduloe inspect to access the current stack frame:
def handle_stackframe_without_leak():
frame = inspect.currentframe()
try:
print inspect.getframeinfo(frame)[2]
finally:
del frame
Diez
Is that possible ?
Yes, use the moduloe inspect to access the current stack frame:
def handle_stackframe_without_leak():
frame = inspect.currentframe()
try:
print inspect.getframeinfo(frame)[2]
finally:
del frame
Diez
sys._getframe() would help you here:
function name is cap
-Peter
这篇关于一个函数可以访问自己的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!