How to write python plug-ins for your own python program?

David M. Cooke cookedm+news at physics.mcmaster.ca
Thu Mar 3 12:48:45 EST 2005


Simon Wittber <simonwittber at gmail.com> writes:

>> 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.

You'd better hope someone doesn't name their plugin
'os; os.system("rm -rf /"); import sys'

Use __import__ instead.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list