I don't get why sys.exit(1) doesn't exit the while loop in the follow case
Steven D'Aprano
steve-REMOVE-THIS at cybersource.com.au
Tue Oct 5 00:42:31 EDT 2010
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?
"while 1" was the accepted idiom for infinite loops in Python for many
years, before the introduction of bools in (I think) Python 2.2. "while
1" is used used as a micro-optimization in versions of Python below (I
think) 2.7. You might prefer "while True" as nicer or even more Pythonic,
but I disagree that "while 1" is misleading.
--
Steven
More information about the Python-list
mailing list