Proper way of handling "plug-in" methods

F

Franck PEREZ

All,

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
application).

Here is the structure I have thought of :

formatting.py
_formattingDict = {} #a dict composed of all available methods, both
builtin and user
def expose(...) : #adds a method to the dict

builtinformatting.py
import myapp.formatting.expose
@expose
def builtinMethod(inputStr) : return someOutput

/home/user/.myapp/customformatting.py
import myapp.formatting.expose
@expose
def customMethod(inputStr) : return someOutput

model.py
#References all the methods, both builtin and custom
execfile("builtinformatting.py")
execfile("/home/user/.myapp/customformatting.py")

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("builtinformatting.py") 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.
Franck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top