import traceback
def _mode():
print "hi---------------------------"
print traceback.extract_stack()[-2][2]
def fun1():
_mode()
def fun2():
_mode()
if __name__ == ‘__main__‘:
fun2()
fun1()
[(‘test_traceback.py‘, 16, ‘<module>‘, ‘fun1()‘), (‘test_traceback.py‘, 8, ‘fun1‘, ‘_mode()‘), (‘test_traceback.py‘, 5, ‘_mode‘, ‘print traceback.extract_stack()‘)]
原文:https://www.cnblogs.com/wangbaojun/p/10573492.html