Re: Using debug print routine inside assert

From: Richard Brodie (R.Brodie_at_rl.ac.uk)
Date: 11/04/03


Date: Tue, 4 Nov 2003 14:22:32 -0000


"Edvard Majakari" <edvard+news@majakari.net> wrote in message
news:8765i072jh.fsf@titan.staselog.com...

> Today I shortly discussed the problems in using print statements for
> debugging problems in Python. Often in coding, in addition to asserts it
> is nice to have a debug routine like

> # somewhere in the program
> debug("subfrobnicate(%s, %s) returned %s" %(p1, p2, subfrobnicate(p1, p2)))
>
> The idea here is to have consistent debug print messages. However,
> parameters or expressions inside the debug statement might be very
> time-consuming to run.

I'm not sure how often you would need to write:

debug("subfrobnicate(%s, %s) returned %s" %(p1, p2, subfrobnicate(p1, p2)))

without having called subfrobnicate in the main code. Assuming that you do,
though, it's relatively easy to juggle around the code by having something like:

def defer(f, *args):
        f(*args)

and writing:

 debug("subfrobnicate(%s, %s) returned %s" % (p1, p2, defer(subfrobnicate, p1, p2)))

Also note that Python now has a standard logging module since 2.3:
http://www.python.org/doc/2.3/whatsnew/



Relevant Pages

  • Re: env variable set using _winreg.SetValueEx() doesnt show w/ os.environ
    ... it works well on WinXP/2K/NT and with Python 2.2 and 2.3. ... (Of course, it wouldn't work for a "limited user" account -- for that case, ... from win32con import WM_SETTINGCHANGE ... if debug: print 'Opening',keypath ...
    (comp.lang.python)
  • Re: python debugging question
    ... Is there any debugging facilities in python which would let me go step ... For python, I am using SPE. ... then you will have a test suite and a "debug" ftn ready to go. ... quick hacks and others that are multi-person, multi-year efforts. ...
    (comp.lang.python)
  • Re: Using python23 to develop an extension for an application that has python22 embedded
    ... > May be it comes down to the approach taken to debug an extension. ... > extension that are not dependent on Python) before attempting to test ... But are you are developing both some Python code and an extension DLL ...
    (comp.lang.python)
  • Re: please include python26_d.lib in the installer
    ... I don't want to build or use the debug version of Python. ... I would prefer manual control over which lib file ... It turns out is is OK to mix runtime libraries *except* in certain ...
    (comp.lang.python)
  • Re: Debugging Python
    ... >> What do people generally use to debug their Python programs? ... "If you don't make mistakes, you don't need a debugger. ...
    (comp.lang.python)