[Tutor] Sharpening the print statement (was:Readlines(longish!))
Michael Janssen
Janssen@rz.uni-frankfurt.de
Sat Jun 28 08:35:02 2003
On Fri, 27 Jun 2003, Alan Gauld wrote:
[discussing a dictionary & function approach]
>
> This removes all the spurious indentation involved in the if
> tests and so maintains the structure of the code and hence
> most of its readability while still providing switched error
> reporting. But it does take more work to set up and maintain...
I've helped myself with two funtions "dprint" and "ddprint" (two levels of
debug-printing are sufficient for me). Both take the error-message and
then check if an option debug or debug2 is True befor printing. That's
all.
This is to say, instead of
if (debug > 1): print "error - messages"
ddprint("error - message")
You can even give those functions some logic to handle objects and tuple
of objects for printing. Then it is easy to turn a debuging-purpose print
statement into one of the debugging functions. As a disadvantage might
count, that you need some more (global?) functions and variables.
Michael