Chris Jerdonek <[email protected]> added the comment:
Eric touched on the use when he said the following above:
> It's nice to be able to distinguish between the failure to *find* the module
> during import from other uses of ImportError.
To make up one example, you might want to use a fallback module if a package
isn't installed:
try:
from fancy_parser import NewParser as HTMLParser
except ModuleNotFoundError:
from html.parser import HTMLParser
But you might still want an error if the package is installed, though
incorrectly (e.g. fancy_parser is installed, but an old version that doesn't
have NewParser). Catching ImportError would swallow this error, whereas
ModuleNotFoundError would let it bubble up.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue15767>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com