Debugging Python ?

John Roth newsgroups at jhrothjr.com
Mon Jul 28 13:23:43 EDT 2003


"Michael Sparks" <zathras at thwackety.com> wrote in message
news:mailman.1059409013.10134.python-list at python.org...
> On Mon, 28 Jul 2003, Shane Hathaway wrote:
>
> > As a bonus, I find that print statements do not rightfully belong in
> > most of the software I write.  Therefore I can happily add print
> > statements anywhere for debugging purposes, knowing that removing them
> > later is perfectly safe.

Yup. AFIC, the print statement is only for debugging, and it's quite
effective for that purpose.

> As an extra bonus, if you do this you can remove them all automatically:
>
> def print(*args):
>    for arg in args:
>       print arg,
>    return True
>
>
> assert print("Well, well, well", "said", "he")
>
> To erase all tracks of the debugging statements at runtime, just use the
> -O flag. I tend to use a variant of this for debugging systems that have
> "complex" concurrency to make it simpler to track "who" "said" what.
>
> I know you can do the same with just grep if you use print - but you have
> to ensure that your debugging statements don't span multiple lines.

Which mine do, quite frequently. By the time you get this far,
you've pretty much got a logging system.

Another interesting arguement for the print statement versus
online debuggers is that, if you practice test driven development,
you gradually lose your facility with the debugger - you use it
so seldom.

John Roth
>
>
> Michael.
>
>






More information about the Python-list mailing list