Plugin system; imp module head scratch

Nick Coghlan ncoghlan at iinet.net.au
Sun Dec 19 07:41:28 CET 2004


Dave wrote:
> Hi, all,
> 
> I'm trying to implement a simple plugin framework, with some
> unexpected results. I'm using Python 2.3.4 on Windows 2000.
> 
> My script loader.py loads plugin packages from a directory (in this
> case its own), and checks a variable defined in the package's
> __init__.py for information on the plugin.

Packages and modules are really rather different beasts. I wouldn't be surprised 
to find that 'find_module' and 'load_module' behave strangely when used for 
packages.

Is there any reason you can't temporarily alter sys.path and use __import__ 
normally? The behaviour of that is generally less quirky.


Anyway, I believe your specific problem is this line:
   return imp.load_module(name, None, '', descr)

Try replacing the empty string in the third argument with the path returned from 
the find_module call. (At the moment, it is pulling in the __init__.py from the 
current directory, and assigning it to the name you requested)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list