I would like to invoke the following code in-situ wherever I refer to MY_MACRO
in my code below.
# MY_MACRO
frameinfo = getframeinf
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()