open() and EOFError

Marko Rauhamaa marko at pacujo.net
Mon Jul 7 14:42:25 EDT 2014


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

> 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.


Marko



More information about the Python-list mailing list