I would like to invoke the following code in-situ wherever I refer to MY_MACRO
in my code below.
# MY_MACRO
frameinfo = getframeinf
I'd say you should define a function to do this, since there are no macros in Python. It looks like you want to capture the current stack frame, which you could do simplify by passing in currentframe()
from the call site to your shared function. Ditto with locals.
def print_frame_info(frameinfo, locals):
msg = 'We are on file ' + frameinfo.filename + ' and line ' + str(frameinfo.lineno)
current_state = locals.items()
def some_other_function:
some_function()
print_frame_info(currentframe(), locals())