How to write python plug-ins for your own python program?
Mark Rowe
mail.python.org at bdash.net.nz
Thu Mar 3 03:54:47 EST 2005
On Mar 3, 2005, at 9:33 PM, Simon Wittber wrote:
>> You mean like 'import'? :)
>
> That's how I would do it. It's the simplest thing, that works.
>
> exec("import %s as plugin" % pluginName)
> plugin.someMethod()
>
> where pluginName is the name of the python file, minus the ".py"
> extension.
A better method would be something along the lines of:
plugin = __import__(pluginName)
plugin.someMethod()
This avoids the potential security problem that `exec' poses as well as
the need to parse + interpret the string.
Regards,
Mark Rowe
<http://bdash.net.nz/>
More information about the Python-list
mailing list