Using the imp module

Fredrik Lundh fredrik at pythonware.com
Tue Oct 10 09:52:49 EDT 2006


Claus Tondering wrote:

>I understand that you can use the imp module to programmatically mimic
> the "import xyzzy" statement.

"imp" sounds like overkill for that purpose; the usual way is do do that is to
explicitly call __import__:

    xyzzy = __import__("xyzzy")

> But is there any way to programmatically mimic the "from xyzzy import
> *" statment?

you can use getattr() to pick out the objects your need.  or you could do
something like:

    globals().update(vars(__import__("xyzzy")))

</F> 






More information about the Python-list mailing list