while 1 vs while True

Peter Otten __peter__ at web.de
Tue Dec 14 09:09:59 EST 2004


Fredrik Lundh wrote:

> Steve Holden wrote:
> 
>> It was unfortunate that so many people chose to use that for
>> compatibility, when if they'd used the same code that the win32all
>> extensions did they could have retained backward compatibility even
>> across a change to constants:
>>
>> try:
>>     True
>> except AttributeError:
>>     True, False = (1==1), (1!=1)
> 
> that doesn't work, though:
> 
> $ python2.1 test.py
> Traceback (most recent call last):
>   File "test.py", line 2, in ?
>     True
> NameError: name 'True' is not defined


Fixing the exception type doesn't help if the change is implemented like the
constancy of None:

>>> try:
...     None
... except NameError:
...     None = object()
...
SyntaxError: assignment to None

Another workaround seems viable:

>>> globals()["None"] = "Evil Nun"
>>> None
>>>

Peter




More information about the Python-list mailing list