try-except syntax

ElChino elchino at cnn.cn
Fri Apr 6 04:08:06 EDT 2018


Steven D'Aprano wrote:

> imp.find_module is deprecated and should not be used in new code.
...

>      try:
>        block
>      except (ImportError, RuntimeError):
>        block

Thanks Steven and others who replied. Looks more elegant.

> By the way, RuntimeError is almost never something you want to catch
> (except to log before bailing out). It should represent a fatal coding
> error, not something safe to ignore.

I was simply playing around with 'imp'. Hence I blocked
RuntimeError.



More information about the Python-list mailing list