binding a reference to a variable

Aahz aahz at pythoncraft.com
Sat Apr 13 13:34:39 EDT 2002


In article <mailman.1018682547.1577.python-list at python.org>,
Tim Peters  <tim.one at comcast.net> wrote:
>
>This is a dodge the Pythonic mind may be too quick to take, though, as about
>once a year it suddenly (re)strikes me how silly the Python idiom
>
>    while 1:
>        line = f.readline()
>        if not line:
>            break
>
>really is <0.9 wink>.  The other 364 days I don't notice the hair.

But it *is* silly.  That's why we have iterators.  One thing I noticed
recently about how fragile the while 1 idiom is: it depends on
readline() returning linebreaks.  Writing a file-like class for which
this *isn't* true breaks the idiom.

I used to say instead, "Yeah, that's a crufty idiom, but it's worth the
pain for all the other features Python gives you, and I *don't* want to
allow 'while line = f.readline()'."
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?



More information about the Python-list mailing list