Best way to work in debug code?

rdudfield at my-deja.com rdudfield at my-deja.com
Mon Jan 17 04:19:08 EST 2000


Hello,


Just wondering how you people write debug code in your functions
/methods?

I personally write a "if (DEBUG_LEVEL >= 5):" around the code.  However
this reduces readability.

To fix the readability problem I usually delete debug code all the
time.  Only having to rewrite it again ( and debug the debug code ).

I sometimes use cvs to find that old debug code, but that's time
consumming.




The way that would be perfect ( for me ) would be for the editor I use(
jed ) to be able to toggle on and off the viewing of debug code, at
different levels of course.  Then have the python interpreter skip over
the debug code, or optimise it out.  One way to do this would be to do
this:

  for x in range(0,100):
    doNonDebugstuff()
  debug 5:
    print len(listOfObjects)
    writeGraphOfObjectsToImage(listOfObjects,"graph.png")
  doMoreNonDebugStuff()

Where debug 5 means "if (DEBUG_LEVEL <= 5):".

You could then call the python interpreter with a debug flag or maybe
call a builtin function to change the debug level.

It would be good to be able to choose to debug at level 4 and below, or
just level 4.



Additions to this might include using strings as debug tags. Like:

debug "functionName":
  doDebugStuff()

Or both.

debug "functionName" 4:
  doDebugStuff()

Being able to tell the interpreter to run all debug code in a particular
function/method/object would be good too.


Rene.




Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list