[Python-Dev] Extended Function syntax

Alex Martelli aleax@aleax.it
Sun, 2 Feb 2003 22:20:59 +0100


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).


Alex