while 1 vs while True

Nick Coghlan ncoghlan at iinet.net.au
Wed Dec 15 10:41:53 CET 2004

Paul Rubin wrote:
> Nick Coghlan <ncoghlan at iinet.net.au> writes:
>>Until this code:
>>.>>> import pdb
>>.>>> pdb.True = 0
>>.>>> pdb.x = "Darn writeable module dictionaries"
>>.>>> from pdb import True
>>.>>> True
>>.>>> from pdb import x
>>.>>> x
>>'Darn writeable module dictionaries'
> If Python really does behave that way, that bug should be fixed immediately.

I tried it out in the 2.4 interpreter before posting it - it certainly does 
behave that way.

And some test frameworks do make use of the capability to inject behaviour into 
the module under test (e.g. the one mentioned here: 

This is behaviour which has been around for a while - and breaking such expected 
behaviour gratuitously isn't acceptable.

PEP 267 discusses a way of speeding access to globals/builtins without giving up 
the external binding of names.


Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia

More information about the Python-list mailing list