[Python-ideas] "While" suggestion

George Sakkis george.sakkis at gmail.com
Thu Jul 3 17:42:44 CEST 2008


On Thu, Jul 3, 2008 at 11:22 AM, Facundo Batista <facundobatista at gmail.com>
wrote:

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.
>
> Regards,
>
> [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
> "do-while".


Actually even more newbies look for a general assignment-as-expression (e.g.
http://tinyurl.com/6bwmp2), so it's not a far step for someone to suggest
for example:

if_stmt ::= "if" expression ["as" target] ":" suite

FWIW I am not necessarily against (rather +0 for now), I'm just pointing out
that striving for coherence just for the sake of it is prone to opening a
can of worms.

Best,
George
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080703/034abd85/attachment.html>


More information about the Python-ideas mailing list