For instanse, I have the following code snippet:
def func1(num):
print(num)
def func2(num):
func1(num)
def func3(num):
func2(num)
func1(num)
def begin():
pass
def print_graph():
pass
def main():
begin()
func3(3)
print_graph()
Is there any simple way to print something like that:
func3(1)
func2(1)
func1(1)
func1(1)
I believe, that I have to use globals()
, but I don't know, what I do next. It is some sort of study task, therefore I cant use any libraries.
How about using decorators to print a function's name when it is called? Something like this:
Then you can wrap each of your functions up:
So that:
Of course there are a lot of assumptions in the above code -- the arguments can be converted to strings, for example -- but you get the picture.