我用下面的代碼的文檔字符串get the caller's method name in the called method:獲得從框架對象
import inspect
def B():
outerframe = inspect.currentframe().f_back
functionname = outerframe.f_code.co_name
docstring = ??
return "caller's name: {0}, docsting: {1}".format(functionname, docstring)
def A():
"""docstring for A"""
return B()
print A()
,但我也想從來電者的方法的文檔字符串中調用的方法。我怎麼做?
函數名稱不一定是它的存儲名稱;您可以像任何其他對象一樣重新分配函數。它們也不總是全局的,類的方法當然不是全局的。 – 2013-03-11 17:02:39
是的,就像我說的,當然不會推薦它,但如果你絕對需要在小程序中快速修復,那麼這是一種可能性 – 2013-03-11 22:05:37