[Python-Dev] Fwd: PEP 310(with-syntax): close synonym of __exit__

Samuele Pedroni pedronis at bluewin.ch
Tue Aug 26 21:38:59 EDT 2003


At 07:02 26.08.2003 -0700, Guido van Rossum wrote:
> > FWIW, I think this has come up before.  For *me*, I think having less
> > magic is worth the pain of adding "__exit__ = close" to a few class
> > statements.  Do you want to add "release" as a synonym too?  I don't.
>
>Agreed.  "Only one way."

your call :).

Btw, if __exit__ is the only spelling then:

   var = expr

   if hasattr(var, "__enter__"):
     var.__enter__()

   try:
     suite

   finally:
     var.__exit__()

is maybe a better semantics. If someone uses some of his
legacy file-like objects etc, but forgets to define at least __exit__, he gets
a fail-fast behavior, otherwise he may have to track down data corruption 
or something
like that...

regards. 




More information about the Python-Dev mailing list