[Python-Dev] Extended Function syntax

Samuele Pedroni pedronis@bluewin.ch
Sun, 2 Feb 2003 22:31:26 +0100


From: "Alex Martelli" <aleax@aleax.it>
> On Sunday 02 February 2003 09:39 pm, Samuele Pedroni wrote:
>    ...
> > > with myfile = auto_closing_file('blah.txt', 'rb'):
> > >   for line in myfile:
>
>   [where here we could also have e.g.
>         xx = myfile.read(23)
>         # rest of suite snipped
>   ]
>
> > >    ...
> >
> > With Guido's 'do', you could define an iterclose():
> >
> > do iterclose(open('blah.txt','rb')): (line):
> >    ...
> >
> > Btw, the two snippets illustrate quite well the different evolutive
> > directions' on the table.
>
> If the Btw does in fact hold, then (speaking as a teacher of Python
> and as a writer) I hope the "with" line prevails -- I would find that
> one trivially easy to explain (even to newbies), while I think I would
> have a harder time teaching the second form (it may have other
> advantages -- I haven't followed the thread well enough to say --
> but it seems it would be harder for newbies to learn and use).

to be fair I don't think that Guido suggested to add a iterclose builtin to the
language, OTOH nobody would be stopped to write and use it in its code,
basically short of community style guides and pressure both:

do iterclose(open('blah.txt','rb')): (line):
    ...

do myfile = autoclose(open('blah.txt','rb')):
   for line in myfile:
    ...

would be potential idioms.