Mart Somermaa wrote:
The variant proposed by Hrvoje Niksic:

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

looks more appealing, but comes with the drawback that sys has to be imported for that purpose only.

That is not a real drawback, as "sys" will certainly be present in the system, so the "importing" boils down to a dict lookup and a variable assignment.

Having said that, I'd add that I found the behavior of __import__ counter-intuitive, but assumed there's a good reason for it. If I hadn't known about sys.modules beforehand, I would have probably gone the chained-getattr route as well.
_______________________________________________
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