Styling Temporary Code

Christian Tanzer tanzer at swing.co.at
Mon Jun 5 01:49:09 EDT 2000


Pete Shinners <pete at visionart.com>:

> one thing i do frequenctly in C is to place temporary
> "debug/doublecheck/sanity" type code while i'm developing
> it. i always put this code in with no indenting, so it's
> easy to spot, work with, and cleanup. it looks something
> like this...
> 
> 
> int myfunc(int nullargs)
> {
>     int newval = do_fancy_stuff(nullargs);
> cout << "newval = " << newval << endl;
>     return more_fancy(newval);
> }
> 
> 
> ok, in this 5 line example it doesn't really sparkly,
> but when i use it in big sections of code, it can't
> be beat. call it the mark of the beast, chase me with
> pitchforks, i simply love it and i don't want to change!
> 
> now in python this obviously won't work, but i haven't
> been able to settle on a style that works for me yet.
> what do other people use for this "working" code?

I use a module-level or class variable `debug_level' which is set to 0
by default. The debugging code looks like:

    if debug_level > x:
        print "newval = %s" % newval

For debugging, I simple change `debug_level' -- normally from outside
the module. 

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list