plugin system?

Rob Brown-Bayliss rob at zoism.org
Wed Apr 2 22:33:37 EST 2003


Whats with the following exec statment?

> In the code, you would instantiate the class with a helper function:
>     def get_plugin_factory(name):
>         # If you have packages (eg monty_python.spam.VikingChorus
>         # or spam.spam.spam.spam.baked-beans.spam) this won't work
>         # as written
>         m, f = name.split(".")
>         d = {}
>         exec "import m" in d
>         return eval(name, d)

I admit I havn't tried it yet, but what does the exec "import m" in d
do?

I had done this in the past:

def change_gear(self,newcog):
  if sys.modules.has_key(newcog):
### CUT SOME GUI SPECIFIC STUFF ###	
  else:
    try:
	setcog = __import__(newcog)
	cog = setcog._setup(self)
	self.caseing.append_page(cog,gtk.Label(newcog))
	self.caseing.set_current_page(self.caseing.page_num(cog))
    except ImportError, msg:

self.caseing is a tabed notbook gui element, and each module imported
(setcog statment) contains code for a new page in the notebook...

How does the __import__(somemodule) differ from the exec line int he
previous example?

Also what happens what I really want to do is create multiple instances
of some "plugin" code using Jeff's example rather than one instance of
it?

The more I think about my problem the more I realise that it's a
combination of changing attributes in the parent object and introducing
new code to modify the behaviour of the parent object... 


-- 

*  Rob Brown-Bayliss
*  =================	
*      zoism.org







More information about the Python-list mailing list