使用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)
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)