open() and EOFError

Marko Rauhamaa marko at
Mon Jul 7 20:42:25 CEST 2014

Steven D'Aprano <steve+comp.lang.python at>:

> try:
>     f = open(path)
> except Whatever:
>     handle_error()
> else:
>     with f:
>         do_stuff()

That's cool. Never really used try-else.

> That gets old really quickly! But then, handling errors is always the
> ugliest part of coding. Hiding the messy details inside a function is
> often a good idea.

There's no way around it; life is messy.


More information about the Python-list mailing list