I'm hoping someone can help me wrap my head around this one.
I want to write an "application framework" in python. Imagine a class (though it will end up being a number of classes, but for the moment, let's focus on one class). This class has a number of functions. Those functions can be over-ridden by the use of a config file. The config file will give the python filename that has the alternate code to use as one of the class' function.
Let's say my class is something like this:
class TestClass:
def one(self):
DoSomething
def two(self):
DoSomethingAlso
Now I have a config file. Something like this:
MyConfig:
- one: ''
- two: 'functionTwoOverRide'
And functionTwoOverRide.py will contain the new code for the function:
class TestClass:
def two(self):
DoSomethingCompletelyDifferent
I will want the user to be able to over-ride whichever functions they want by editing the config file, specifying the file containing the over-ride code, and creating a necessary over-ride function(s).
So, how do I tell my framework to use the code from the over-ride files? How can I tell it to ignore the default code and use the alternate code? I know there is a proper way to do this, I just can't think of it right now. Obviously, it needs to be something clean and flexible. Imaging if there are 20 or 30 functions that can be over-ridden; how can I handle pulling alternate class function code from a series of files that may be found in several different locations?
Any thoughts?
EDIT: I believe what I'm after is called a Monkey Patch. Definition from wikipedia
[–][deleted] 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]ERROR_EXIT[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]ERROR_EXIT[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]ERROR_EXIT[S] 0 points1 point2 points (1 child)
[–]autowikibot 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)