Recipes for trace statements inside python programs?

samwyse samwyse at gmail.com
Thu Jun 25 07:22:39 EDT 2009


I use an @trace decorator.  This (http://wordaligned.org/articles/
echo) will get you started but there are lots of others available.  My
personal preference is a decorator that catches, displays and re-
raises exceptions as well as displaying both calling parameters and
returned values.

btw, here's a cool Python3K (or 2.6 if you turn on print functions)
trick that's sort-of on topic since it relates to log files and such:
import functools, sys
warn = functools.partial(print, file=sys.stderr)
logfile = open(...)
log = functools.partial(print, file=logfile)
# etc.

On Jun 25, 3:33 am, Francesco Bochicchio <bieff... at gmail.com> wrote:
> Hi all,
>
> as many - I think - python programmers, I find muself debugging my
> scripts by placing print statements in strategic places rather than
> using the python debugger, and commenting/uncommenting them according
> to myy deugging needs.  After a time, these prints staements start to
> evolving in some ad-hoc half-baked framework ... so I wonder if there
> is somewhere there is a full-baked trace statement support framework
> which I can use. I'm aware of the logging module, but for me it its
> more geared toward  application logging rather than toward trace for
> debugging purpose.



More information about the Python-list mailing list