Dynamic loading of modules

dougfort dougfort at dougfort.net
Mon Sep 23 15:07:47 EDT 2002


On Mon, 23 September 2002, "Andreas Lydersen" wrote:

> 
> 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")
> 
> I have tried 'exec "plugins.Password"', and that works.  However, I
need to
> get a list of pointers to the modules I import in order to work with them
> later.
> 
> Bottom line is:  I need to know how to dynamically load modules and get a
> pointer to the same module.
> 
> Any help is appreciated.
>
Here's something my friend Joe found for a project we're working on
 
Regarding loading python "modules" from a directory... check out:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82234

Additional info:

Title: Importing a dynamically generated module 
Submitter: Anders Hammarquist (other recipes) 
Last Updated: 2001/10/17 
Version no: 1.0 
Category: System


Doug Fort <dougfort at dougfort.net>
http://www.dougfort.net




More information about the Python-list mailing list