I don't get why sys.exit(1) doesn't exit the while loop in the follow case

Peter Otten __peter__ at web.de
Mon Oct 11 08:13:37 EDT 2010


Steven D'Aprano wrote:

> On Tue, 05 Oct 2010 13:57:11 +1100, Ben Finney wrote:
> 
>> chad <cdalten at gmail.com> writes:
>> 
>>> while 1:
>> 
>> A minor point: this is more explanatory and less misleading if you write
>> it as ‘while True’.
> 
> Why is it misleading? Is there some circumstance in Python where the
> literal 1 could have a false value?

Wrong question.

>>> while True:
...     print "forever"
...
>>> True
0

So, if I were to play advocatus diaboli I'd argue that 'while True: ...' is 
more likely to mislead because 'True' could be anything.

Peter

PS: The above is no longer possible in Python 3 where True and False have 
become keywords.



More information about the Python-list mailing list