ANN: watch.py - a handy debugging tool

Olivier Dagenais olivierS.dagenaisP at canadaA.comM
Wed Oct 18 23:53:52 EDT 2000


Because I can't use the debugger to debug, sprinkling 'print' statements all
over the place seems to be the answer.  However, this doesn't do it.  I
mean, "print secretValue" only spews out a value and this gets complicated
if you have other "print" statements sprinkled in your code.  So then you
write "print 'secretValue = %s' % secretValue".  This gets old REALLY FAST!

So I wrote watch.py and made it so you only need to type "watch
 secretValue )" and the variable name, type, value and the line number and
source file the call originated are printed.

For example, the test code included in watch.py

if __name__ == "__main__":
    a = "something else"
    secretOfUniverse = 42
    watch ( a )

    watch ( secretOfUniverse )

prints out the following:

C:\Program Files\Python\Lib>python watch.py
Variable 'a' of type 'string' == 'something else' at line 22 of file
'watch.py'
Variable 'secretOfUniverse' of type 'int' == '42' at line 24 of file
'watch.py'


Just thought I'd give this out to everybody because I'm sure I'm not the
only one who could really use this.  Of course, if bad stuff happens, I
didn't do it, it's your own fault, blah, blah, blah.  There's virtually no
comments, I pulled this out of my hat by trial-and-error and by scouting the
documentation for Python internals.

So... throw a copy of watch.py in your python/lib directory, add the line
"from watch import watch" at the top of your program, sprinkle some calls to
watch all over the place and thank me by sending me large amounts of money.

maybe-I-should-have-called-this-module-trace-instead-ly y'rs

--
----------------------------------------------------------------------
Olivier A. Dagenais - Software Architect and Developer
"Someone called 'Type your name here' is impersonating me on the
internet and is posting exactly the same things I am posting!"




begin 666 watch.py
M:6UP;W)T('1Y<&5S+"!S=')I;F<-"F9R;VT@=')A8V5B86-K(&EM<&]R=" J
M#0HB(B)3:&]U;&0@<')I;G0@;W5T('-O;65T:&EN9R!L:6ME#0H)(E9A<FEA
M8FQE("=X)R!O9B!T>7!E("=S=')I;F<G(#T]("=A8F-D968G(&%T(&QI;F4@
M,C,T(&]F(&9I;&4@)V)L87)G+G!Y)R(-"B(B(@T*9&5F('=A=&-H("@@=F%R
M:6%B;&4@*3H-"@ES=&%C:R ](&5X=')A8W1?<W1A8VL@*" I6RTR.EU;,%T-
M"@EA8W1U86Q#86QL(#T@<W1A8VM;,UT-"@EL969T(#T@<W1R:6YG+F9I;F0@
M*"!A8W1U86Q#86QL+" G*"<@*0T*"7)I9VAT(#T@<W1R:6YG+G)F:6YD("@@
M86-T=6%L0V%L;"P@)RDG("D-"@EV87)4>7!E(#T@='EP92 H('9A<FEA8FQE
M("D-"@EP<FEN=" B5F%R:6%B;&4@)R5S)R!O9B!T>7!E("<E<R<@/3T@)R5S
M)R!A="!L:6YE("5D(&]F(&9I;&4@)R5S)R(@)2 H#0H)"7-T<FEN9RYS=')I
M<" H(&%C='5A;$-A;&Q;;&5F="LQ.G)I9VAT72 I+ T*"0ES='(H=F%R5'EP
M92E;-SHM,ETL#0H)"79A<FEA8FQE+ T*"0ES=&%C:ULQ72P-"@D)<W1A8VM;
M,%T@*0T*#0II9B!?7VYA;65?7R ]/2 B7U]M86EN7U\B. at T*"6$@/2 B<V]M
M971H:6YG(&5L<V4B#0H)<V5C<F5T3V95;FEV97)S92 ](#0R#0H)=V%T8V@@
I*"!A("D-"@T*"7=A=&-H("@@<V5C<F5T3V95;FEV97)S92 I"0T*#0H`
`
end




More information about the Python-list mailing list