Using the imp module

Fredrik Lundh fredrik at
Tue Oct 10 15:52:49 CEST 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:



More information about the Python-list mailing list