Message207337
| Author |
r.david.murray |
| Recipients |
brett.cannon, eric.snow, larry, ncoghlan, r.david.murray, vstinner |
| Date |
2014年01月05日.03:15:09 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1388891709.3.0.34224301299.issue20123@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Is it the case that given a filename, it might be possible to load a module even if open(filename) fails?
I think the logic is clearer in the form where it is not pulled out into a separate helper function. You can avoid the double check on the extension by doing:
if filename.endswith(importlib.machinery.BYTECODE_SUFFIXES):
loader = importlib.machinery.SourcelessFileLoader('__temp__',
filename)
elif filename.endswith(importlib.machinery.EXTENSION_SUFFIXES):
loader = importlib.machinery.ExtensionFileLoader('__temp__',
filename)
else:
loader = None
if loader:
xxxxx
else:
xxxxx |
|