Mart Somermaa wrote:
I meant that you have to

import sys

only to access sys.modules (i.e. importing sys may not be necessary otherwise).

I understand that, but I'm arguing that that's a non-problem. Importing sys is a regular thing in Python, not an exception. You need sys to get to sys.argv, sys.exit, sys.stdout, etc. -- it's not like sys is an infrequently used module. Since sys is always present, importing it is not an efficiency problem, either.

mod = __import__(modname, submodule=True)

with

import sys
__import__(modname)
mod = sys.modules[modname]

"import sys" is normally located near the beginning of the file (and needed by other things), so the actual code snippet would really contain only those two lines, which don't strike me as bad. Ideally, __import__ would simply return the "tail" imported module in the first place, but I don't think introducing a boolean keyword argument really improves the design.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to