Message312996
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. |
|
Date |
User |
Action |
Args |
2018-02-27 11:27:27 | chris.jerdonek | set | recipients:
+ chris.jerdonek, gvanrossum, barry, brett.cannon, theller, jcea, pitrou, ezio.melotti, Arfrever, cvrebert, asvetlov, python-dev, eric.snow, serhiy.storchaka, Guido.van.Rossum, cwg |
2018-02-27 11:27:27 | chris.jerdonek | set | messageid: <1519730847.09.0.467229070634.issue15767@psf.upfronthosting.co.za> |
2018-02-27 11:27:27 | chris.jerdonek | link | issue15767 messages |
2018-02-27 11:27:27 | chris.jerdonek | create | |
|