On Wed, Jul 28, 2010 at 10:07 AM, Mac Ryan <quasipe...@gmail.com> wrote:
> Hi everybody, > > Mac, I don't know if this is exactly what you are after, but I created a poor-man's plugin system by simply putting .py files into the same directory as my app and naming them like xxxx_plugin.py Each of these .py "plugins", had to define a class named "Plugin" that had some set of expected methods and properties (ex: initialize(), run(), etc.). Then, when my app started up, it simply got a list of all the "*_plugin.py" files in the current directory, dynamically imported the files using "my_module = __import__(name)" and then I could do whatever I wanted with that module using "my_module", such as instantiate an object for each module's "Plugin" class, etc. Actually, here's a snippet of code I had lying around that I slapped together a few years ago to remind myself of how I did this. I can't promise this is 100% tested, but it should give you an idea. http://pastebin.com/UtVp6J9j Also, you might want to look at this discussion: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba8d361516403fdf/ Best of luck! -Scott
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor