How can I print every function/method call ?
I have tried to use : python -m trace --trace
but it prints also the function inner code... I just want functions names that were called.
using traceback in code prints the last function called before calling the command itself, and the code contains many classes...
You may find -l
useful.
main.py:
def foo():
pass
def bar():
pass
foo()
bar()
Doing
$ python -m trace -l main.py
outputs
functions called:
filename: C:\Python34\lib\trace.py, modulename: trace, funcname: _unsettrace
filename: main.py, modulename: main, funcname: <module>
filename: main.py, modulename: main, funcname: bar
filename: main.py, modulename: main, funcname: foo
Depending on the number of functions you have, you may find a decorator more suitable:
def print_deco(func):
def inner(*args, **kwargs):
print(func.__name__)
return func(*args, **kwargs)
return inner
@print_deco
def foo():
pass
@print_deco
def bar():
pass
foo()
bar()
# foo
# bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With