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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to