ANNOUNCE: A Python 2.1 release candidate!

Don O'Donnell donod at home.com
Sat Apr 14 02:06:04 EDT 2001


Guido van Rossum wrote:
> 
> Python 2.1 is almost ready.  We've built a release candidate -- a
...
>   - After a public outcry, assignment to __debug__ is no longer illegal;
>     instead, a warning is issued.  It will become illegal in 2.2.
...

I can well imagine that there would be a public outcry, and although
this is the first I've heard of it, let me add my voice to the chorus.

I use the __debug__ built-in variable, not only for it's intended use as
an implied conditional on the assert statement, but also explicitly as a
conditional on print statements used for debugging, as:
    if __debug__: print "function bleep entered with arg: %s" % arg
thus all debugging is under control of a single variable.

I find it very useful to be able to assign to __debug__.  There are at
least two situations where I use it regularly:

1.  As a run-time debugging switch.  By providing an interactive user
option switch which sets __debug__ to 0 or 1 dynamically at run time
through user input (menu or command prompt).  This allows me to easily
turn off debugging when it's not needed and turn it back on when it is. 
This can save me a lot of time in not having to watch thousands of lines
of unneeded debugging information scroll up my screen.  Especially true
in early stages of testing, where I just want the compiler diagnostics
and run-time exception handler to do my first level checking.

2.  To selectively turn off debugging for sections of code or functions
which have been tested, and turn it on for code sections under test. 
This also saves a lot of unnecessary output, and allows me to leave the
debugging code in for possible future use if the code needs to be
modified or refactored.

Without the ability to rebind the __debug__ variable, the only method I
know of to change it at present is through the python command line
option -O.  But since I normally do unit and system testing in Python
interactive mode, that would require exiting and re-executing python
every time I wanted to change the debug setting, or else have two
separate sessions running, one with the -O switch set and one without. 
And that's just plain silly.

Can anyone explain to me why this change, to make __debug__ read only,
is necessary or beneficial in some way?  Or am I misinterpreting GvR's
statement that "assignment to __debug__ ... will become illegal in 2.2."

Thanks,
-Don



More information about the Python-list mailing list