[Python-Dev] Re: anonymous blocks
Terry Reedy
tjreedy at udel.edu
Mon Apr 25 16:14:07 CEST 2005
"Fredrik Lundh" <fredrik at pythonware.com> wrote in message
news:d4i6hg$q88$1 at sea.gmane.org...
> Guido van Rossum wrote:
>
>> At the same time, having to use it as follows:
>>
>> for f in with_file(filename):
> < for line in f:
>> print process(line)
>>
>> is really ugly, so we need new syntax, which also helps with keeping
>> 'for' semantically backwards compatible. So let's use 'with', and then
>> the using code becomes again this:
>>
>> with f = with_file(filename):
>> for line in f:
>> print process(line)
>
> or
>
> with with_file(filename) as f:
with <target> as <value>:
would parallel the for-statement header and read smoother to me.
for <target> as <value>:
would not need new keyword, but would require close reading to distinguish
'as' from 'in'.
Terry J. Reedy
More information about the Python-Dev
mailing list