open() and EOFError

Gregory Ewing greg.ewing at
Tue Jul 8 00:09:07 CEST 2014

Marko Rauhamaa wrote:
>     with open(path) as f:
>         ...
> If the open() call is guarded against exceptions (as it usually should),
> one must revert to the classic syntax:

Hmmm, maybe we could do with a with-except statement:

    with open(path) as f:
    except IOError:
       # Catches exceptions in the with-expression only

Although that would be a bit confusing.


More information about the Python-list mailing list