python打印函数调用关系

使用python时,当想知道是哪里 调用的特定代码时,可在此特定代码前加下列语句:   网上搜到的其他信息 不如这个全  :)

import sys
print ("--- current function is      ", sys._getframe().f_code.co_name)
print ("--- current function from ", sys._getframe().f_code.co_filename)
print ("--- called by function      ", sys._getframe().f_back.f_code.co_name)
print ("--- called at line               ", sys._getframe().f_back.f_lineno)
print ("--- called from file           ", sys._getframe().f_back.f_code.co_filename)


猜你喜欢

转载自blog.csdn.net/anthea_luo/article/details/80514631