[Python-Dev] __import__ problems
Mart Somermaa
mrts at mrts.pri.ee
Fri Nov 28 13:59:39 CET 2008
Nick Coghlan wrote:
> As Hrvoje has pointed out, 'sys' is part of the internal interpreter
> machinery - it's there as soon as the interpreter starts. The import
> call for it just grabs it out of the module cache and creates a
> reference to it in the current namespace.
I understand that, but
Explicit is better than implicit.
--> non-explicit import sys and __import__(modname) to access
sys.modules[modname]
Simple is better than complex.
--> three lines for a common use case instead of one
Readability counts.
--> why is sys imported in this WSGI app (that shouldn't generally
touch any of the common sys.argv, sys.stdout etc)?!
(500 lines later) aha, to access sys.modules
There should be one-- and preferably only one --obvious way to do it.
--> should I use the 3-line idiom? should I use the getattr() idiom?
Ideally, __import__() should support the only obvious way.
In short, the three-line version doesn't convey the intent in an obvious way and does more work than is necessary.
More information about the Python-Dev
mailing list