[Python-ideas] "While" suggestion

Torsten Bronger bronger at physik.rwth-aachen.de
Thu Jul 3 19:11:02 CEST 2008


Facundo Batista writes:

> 2008/7/3 Stavros Korokithakis
> <stavros at korokithakis.net>:
>> while my_file.read(1024) as data:
>>   do_something(data)
> Python explicitly disallows inline assignment ("while
> a=myfile.read():") because of the error propensity when confusing
> it with the comparation ("=="). But here we're gaining the same
> advantage, without that risk.
> So, taking into account that...
> a) We already have "as" as an statement.
> b) We already use "as" as an assignment [1]
> c) This will allow more concise and intuitive code
> ... I'm definitely +1 to this proposition.

I don't like it.  Taken as an English expression, it suggests
something misleading.  I looked at my own code (not much; 15.000
lines) and found three "while True", and none of them could be
expressed with "while ... as ...".  It is not worth it in my

However, it *is* an issue in Python.  The almost official
repeat...until is "while True:", and I got accustomed to reading it
as a repeat...until.  But actually, it is even more flexible since
it is the most general loop at all.

Granted that "while True" is not eye-pleasant.  Maybe we could
introduce the idion "while not break:".  ;-)


Torsten Bronger, aquisgrana, europa vetus
                   Jabber ID: torsten.bronger at jabber.rwth-aachen.de

More information about the Python-ideas mailing list