Proper way of handling "plug-in" methods

Franck PEREZ franck.perez at
Mon Jan 8 12:49:15 CET 2007


My application deals with strings formatting. I have built-in methods
but I also expect the user to add its methods in its own .py files
(some sort of plugin methods, all user methods should be exposed in my

Here is the structure I have thought of :
_formattingDict = {} #a dict composed of all available methods, both
builtin and user
def expose(...) : #adds a method to the dict
import myapp.formatting.expose
def builtinMethod(inputStr) : return someOutput

import myapp.formatting.expose
def customMethod(inputStr) : return someOutput
#References all the methods, both builtin and custom

Expected result after the execfile : formatting._formattingDict
contains the 2 methods builtinMethod and customMethod

Is this a proper way of structuring my application ? Do you see
anything better ?

Moreover, I dislike execfile("") since classic
import would do the job. However I first wanted a united method for
both builtin and custom scripts since it is the same logic for me.

Thanks very much in advance for your advice.

More information about the Python-list mailing list