Dynamic loading of modules

Henrik Motakef henrik.motakef at web.de
Mon Sep 23 15:33:21 EDT 2002


"Andreas Lydersen" <al at metroic.no> writes:

> Hi,
> I'd like to load a set of modules from a directory.  I have tried to use the
> __import__(...) statement to do so, but with no success.
> ¨
> The static approch works (of course), but the dynamic does not!
> 
> static:
> import plugins.Password
> 
> dynamic atttempt:
> __import__("plugins.Password")

__import__ doesn't really import the module, it returns a module
object. So do something like

>>> pwd = __import__("plugins.Password")
>>> pwd.spam()
Spam!

hth
Henrik



More information about the Python-list mailing list