When debugging, I like to print out all the inputs and outputs of a function (I know I need a better IDE, but humour me, this could be used for error reporting). So, I\'d id
Use a debugger. Seriously. Decorating every function you want to keep track is a bad idea.
Python has a debugger included, so you don't need a good IDE.
If you don't want to use a debugger, you can use the trace function.
import sys
@sys.settrace
def trace_debug(frame, event, arg):
if event == 'call':
print ("calling %r on line %d, vars: %r" %
(frame.f_code.co_name,
frame.f_lineno,
frame.f_locals))
return trace_debug
elif event == "return":
print "returning", arg
def fun1(a, b):
return a + b
print fun1(1, 2)
That prints:
calling 'fun1' on line 14, vars: {'a': 1, 'b': 2}
returning 3
3
Even easier would be to use Winpdb:
It is a platform independent graphical GPL Python debugger with support for remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.
Features:
(source: winpdb.org)