Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: while True or while 1 Date: Mon, 23 Jan 2012 15:51:37 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: <4F1AC1D4.2080402@gmail.com> NNTP-Posting-Host: dsl.comtrol.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1327333897 2028 64.122.56.22 (23 Jan 2012 15:51:37 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 23 Jan 2012 15:51:37 +0000 (UTC) User-Agent: slrn/pre0.9.9-102 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19266 On 2012-01-21, Erik Max Francis wrote: > Chris Angelico wrote: >> On Sun, Jan 22, 2012 at 12:47 AM, Andrea Crotti >> wrote: >>> So I tried to do the following, and the result is surprising. For what >>> I can see it looks like the interpreter can optimize away the 1 boolean >>> conversion while it doesn't with the True, the opposite of what I >>> supposed. >>> >>> Anyone can explain me why is that, or maybe is my conclusion wrong? >> >> In Python 3, they compile to the same code, because 'True' is a >> keyword. In Python 2, you can reassign True to be 0. > > Why this should concern anyone, I don't know; I don't think it does concern anybody (except the compiler, who treats all identifiers the same). [...] > The real reason people still use the `while 1` construct, I would > imagine, is just inertia or habit, That's certain why I do it. It's left over from the days when C and Python didn't have symbolic boolean "constants". > rather than a conscious, defensive decision. If it's the latter, > it's a case of being _way_ too defensive. -- Grant Edwards grant.b.edwards Yow! Hmmm ... A hash-singer at and a cross-eyed guy were gmail.com SLEEPING on a deserted island, when ...