For debugging purposes I would like to get the source code of the function that has called my function. So in the following situation:
def calling_func():
x = 123
y = x + 1
myfunc()
def myfunc():
calling_source = f()
I would like a function f, such that calling_source becomes the string
"""
x = 123
y = x + 1
myfunc()
"""
Does such a function exist? I'm guessing that this might be possible with something like sys._current_frames and the inspect module.
strobject? Why not just use a modern debugger in the text editor of your choice with break points etc? Then you can step through the call stack with the source code in front of you.