debug print shortcut?

Donald 'Paddy' McCarthy paddy3118 at netscape.net
Sun Jun 6 15:09:05 CEST 2004


John Mudd wrote:

> When debugging python, I add print statements such as these.  
> 
> print 'i=%s' % `i`
> print 'foo()=%s' % `foo()`
> print 'a,b,c=%s' % `a,b,c`
> 
> I just want to dump the value of a variable or expression.  But I
> don't like having to type the expression twice, everytime.  I can
> solve this in 'C' with a preprocessor macro.  Can it be solved in
> python?
> 
> John
I found this:

 >>> def dump(s, glob, loc):
... 	print "%s = %s\n" % (s, eval(s,glob,loc) )
...
 >>> a=55
 >>> dump("a",globals(),locals())
a = 55

 >>>


Cheers, Pad.




More information about the Python-list mailing list