Possible to import a module whose name is contained in a variable?

Ed Leafe ed at leafe.com
Mon Mar 7 08:28:01 EST 2005


On Mar 7, 2005, at 5:23 AM, Michael Hoffman wrote:

> Avoiding exec (which is a statement, not a function) is much more
> important. Since it executes arbitrary code, you can get unpredictable
> results from it.

	Is there any way to use __import__ to replace the following:

exec("from %s import *" % modulename)

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://dabodev.com/
  Come to PyCon!!!!  http://www.python.org/pycon/2005/




More information about the Python-list mailing list