[Python-ideas] "While" suggestion

Facundo Batista facundobatista at gmail.com
Thu Jul 3 17:22:16 CEST 2008

2008/7/3 George Sakkis <george.sakkis at gmail.com>:

> There is already an idiom for this, although admittedly not obvious or
> well-known:
> for data in iter(lambda: my_file.read(1024), ''):
>     do_something(data)
> or in 2.5+:
> from functools import partial
> for data in iter(partial(my_file.read,1024), ''):
>     do_something(data)

Yes, but note that these feels like workarounds.

One thing that I love in Python is that you can learn a concept, and
apply it a lot of times.

So, suppose I'm learning Python and find that I can do this...

  with_stmt ::=  "with" expression ["as" target] ":" suite

...why can't I do this?:

  while_stmt ::=  "while" expression ["as" target]  ":" suite

I mean, I don't care if this solves a lot of issues, or just a few
[1]... this just make the whole syntax more coherent.


[1] Note, however, that one of the issues that it solves is one that
raises always a lot of questions for newbies... how to make a

. Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

More information about the Python-ideas mailing list