nospam at nowhere.com
Sun Oct 31 02:37:19 CEST 2004
On Sat, 30 Oct 2004 07:58:27 -0700, Josiah Carlson wrote:
> 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
> ...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'):
> globals()[fn] = \
> __import__('plugins.%s'%fn, globals(), locals(), [fn])
> Etcetera. May not be the best, but it will get the job done.
> - Josiah
Just FYI, dynamically loaded plugins will not be caught by tools like
py2exe. Another mechanism, which may be more py2exe friendly, is to make
a tool which dynamically creates a python file, which lists all of the
imports. That way, you import the dynamically created file, but once it's
created, you immediately leverage the file for use with py2exe, which can
now follow all of the imports.
Of course, if you never plan on being a py2exe user, you can happily
ignore my ramblings. ;)
More information about the Python-list