考慮以下偽代碼:func1(): func2() #func2 is called inside func1我的問題是,我可以在func2中訪問調用它的函數的名稱嗎?在這種情況下,func1?謝謝!
1 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
import inspect
def func2():
cframe = inspect.currentframe()
func = inspect.getframeinfo(cframe.f_back).function
print 'called from ' + func
def func1():
func2()
func2()
func1()
輸出:
called from <module>
called from func1
添加回答
舉報
0/150
提交
取消