[Python-Dev] Merging PEP 310 and PEP 340-redux?
Eric Nieuwland
eric.nieuwland at xs4all.nl
Thu May 12 07:12:50 CEST 2005
Guido van Rossum wrote:
> class locking:
> def __init__(self, lock): self.lock = lock
> def __enter__(self): self.lock.acquire()
> def __exit__(self, *args): self.lock.release()
>
> class opening:
> def __init__(self, filename): self.filename = filename
> def __enter__(self): self.f = open(self.filename); return self.f
> def __exit__(self, *args): self.f.close()\
>
> And do EXPR as VAR: BLOCK would mentally be translated into
>
> itr = EXPR
> VAR = itr.__enter__()
> try: BLOCK
> finally: itr.__exit__(*sys.exc_info()) # Except sys.exc_info() isn't
> defined by finally
In this example locking's __enter__ does not return anything.
Would
do EXPR:
BLOCK
also be legal syntax?
-eric
More information about the Python-Dev
mailing list