I would like to invoke the following code in-situ wherever I refer to MY_MACRO
in my code below.
# MY_MACRO
frameinfo = getframeinf
MacroPy is a project of mine which brings syntactic macros to Python. The project is only 3 weeks old, but if you look at the link, you'll see we have a pretty cool collection of demos, and the functionality you want can definitely be implemented using it.
On the other hand, python has some pretty amazing introspection capabilities, so I suspect you may be able to accomplish what you want purely using that functionality.