Python gets the name and line number of the function where the current position is located
C + + program debugging often used in several macros: __file__, __function__, __line__, recently written Python program encountered problems debugging also want to use this way, looked for the next online data, found that there are many people ask, estimates are like me just from C /c++ go to Python's bar. The function name and line number in Python where the current position is obtained are encapsulated in SYS and are obtained as follows:
Import sys def get_cur_info (): Print Sys._getframe (). F_code.co_filename #当前文件名, you can get print sys._getframe through __file__ (). F_code.co_name #当前函数名 Print Sys._getframe (). F_lineno #当前行号 Get_cur_info ()
Other functions Please refer to: Dir (Sys._getframe ()).
Turn from: http://www.5dcode.com/?p=551