Debugging Techniques I

#def my_problematic_function(x):
def my_problematic_function(x, call_count=[]):
    call_count.append(1)
    print("ZMD DEBUG call #{}".format(len(call_count)))
    import traceback; traceback.print_stack()
    result = do_stuff(x)
    etc()

One thought on “Debugging Techniques I

  1. I'm probably greatly exaggerating the problem, but wouldn't that end up taking a lot of memory if you have many functions like that and you call them all many times? Or are arrays in python lazy? Either way, my inner perfectionist would change the first three lines to this:

    def my_problematic_function(x, call_count=[0]):
    call_count[0] += 1
    print("ZMD DEBUG call #{}".format(call_count[0]))

    It's not any more complicated, but more efficient, unless I'm missing something.

Leave a Reply

Your email address will not be published. Required fields are marked *