[Python-Dev] Extended Function syntax
Moore, Paul
Paul.Moore@atosorigin.com
Mon, 3 Feb 2003 09:59:59 -0000
From: Alex Martelli [mailto:aleax@aleax.it]
> On Sunday 02 February 2003 11:07 pm, Brett Cannon wrote: ...
>
> > Now if ``__exit__()`` would be executed regardless of exceptions
> > this would probably eliminate a decent chunk of code that uses
> > ``finally:``
>
> Hmmm, yes, I _was_ sort of assuming that __exit__ runs much like
> 'finally' would -- otherwise cleanup/release code would more often
> than not have to be duplicated.
I don't think there's much point to new syntax if __exit__ *doesn't*
run even in the face of exceptions. To my mind, that's the whole point
of the construct - guaranteed cleanup.
> > Either way this seems rather nice. And if you can pass in arguments
> > (as I think ``FILE =3D file('blah.txt', 'rb'): (some_argument):`` is
> > supposed to implement) this would be really nice. =3D)
>
> I think THAT is the complicated part of the "do" syntax -- that
> trailing "(whatever):" that I don't understand. What would its pluses
> be? Where would that 'whatever' be directed to...? Could you please
> provide a use case for with + "(some_argument):" ...?
Having just seen Samuele's examples, I notice that he uses the trailing
argument. And I still don't understand it :-( There's no way I can see
the "do" syntax as even remotely natural for the example of a file
autoclose (and by inference, any reasonably common cleanup requirement).
Is there any additional advantage to the "do" syntax that isn't shared =
by
the "with" syntax? A full example like the autoclose one would help
enormously!
Paul