open() and EOFError

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Jul 7 18:09:07 EDT 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.

-- 
Greg



More information about the Python-list mailing list