[Python-Dev] Extended Function syntax
Samuele Pedroni
pedronis@bluewin.ch
Tue, 4 Feb 2003 20:05:44 +0100
From: "Paul Moore" <lists@morpheus.demon.co.uk>
> Oren Tirosh <oren-py-d@hishome.net> writes:
>
> > I agree. I don't see anything wrong with
> >
> > f=open('spam', 'r')
> > with autoclose(f):
> > ...
>
> I *like* this way of doing autoclose files. Much better than the way
> I've been thinking
>
> f = autocloser("spam")
> with f:
> ...
>
> > and I think that
> >
> > with autolock(obj):
> > ...
> >
> > looks better than any other alternative proposed so far.
>
> On the other hand, I quite like
>
> with lock:
> ...
>
> (where lock is defined appropriately).
>
> I don't know. Does the fact that the same statement is best used in
> two subtly different ways (permanent object vs throwaway helper
> object) count as a disadvantage of the statement (in terms of
> teachability, if nothing else...)?
it depends on how you look at things, either your main object support the
'with' protocol or not:
with with_proto_supporting_object:
...
or it needs an adapter:
with with_proto_adpater(obj):
...
Anyway write the PEP and leave this behind you <wink>.