[Python-Dev] With statement

Alex Martelli aleax@aleax.it
Tue, 4 Feb 2003 21:23:10 +0100


On Tuesday 04 February 2003 06:19 pm, Duncan Booth wrote:
> On 4 Feb 2003 at 17:02, Moore, Paul wrote:
> > # You do realise you can't use a raw file object here really?
>
> Unless of course the file object sprouted an __exit__ method.

Yep, just an
    __exit__ = close
in class scope would do it, if "class file(object):" was coded in Python;-)

> It's probably worth including the pro's and con's of that in
> your PEP.

Particularly the con's, if you can think of any.  Me, I can't.

> I can see people falling into the trap of expecting the file
> object to 'do the obvious thing' here (Neal Norwitz being the
> first, but almost certainly not the last).

Indeed, why _shouldn't_ file do the obvious thing?  Just
like it has a __del__ = close, so should it have an __exit__
(the latter only if with IS introduced, of course).


Alex