Plugin system

Josiah Carlson jcarlson at uci.edu
Sat Oct 30 10:58:27 EDT 2004


Reinhold Birkenfeld <reinhold-birkenfeld-nospam at wolke7.net> wrote:
> 
> Irmen de Jong wrote:
> > Reinhold Birkenfeld wrote:
> > 
> >> How would you implement a plugin system (for a web-based application)?
> > 
> > This is so general a question that I cannot think of anything concrete to answer.
> > Please ask again, with more detail about what you want/need/have in mind.
> 
> Okay, the question is too open: My focus is on how you would structure
> the plugin code (directories, files) and how you would write code to
> load these plugins.

...Have a place for plugins
app/plugins

...Load the plugins on startup
import traceback
import os
for fn in os.listdir('plugins'):
    if fn[:1] != '_' and fn.split('.')[-1] in ('py', 'pyw'):
        try:
            globals()[fn] = \
              __import__('plugins.%s'%fn, globals(), locals(), [fn])
        except:
            traceback.print_exc()

Etcetera.  May not be the best, but it will get the job done.

 - Josiah




More information about the Python-list mailing list