Message312996
| Author |
chris.jerdonek |
| Recipients |
Arfrever, Guido.van.Rossum, asvetlov, barry, brett.cannon, chris.jerdonek, cvrebert, cwg, eric.snow, ezio.melotti, gvanrossum, jcea, pitrou, python-dev, serhiy.storchaka, theller |
| Date |
2018年02月27日.11:27:27 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1519730847.09.0.467229070634.issue15767@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|