Adding Macros to Python

前端 未结 7 976
无人及你
无人及你 2021-02-02 07:41

I would like to invoke the following code in-situ wherever I refer to MY_MACRO in my code below.

# MY_MACRO
frameinfo = getframeinf         


        
7条回答
  •  伪装坚强ぢ
    2021-02-02 08:16

    If you need only line and function name of caller like I needed for debug, you can get caller function information by inspect.getouterframes link.

    import inspect
    def printDebugInfo():
      (frame,filename,line_number,function_name, lines, 
        index) = inspect.getouterframes(inspect.currentframe())[1]
      print(filename, line_number, function_name, lines, index)
    
    def f1():
      printDebugInfo()
    
    if __name__=='__main__':
      f1()
    

提交回复
热议问题