lundi 20 juin 2016

How to make dynamic stub functions on the fly?


I have a class with about 200 stub functions, they look something like this:

def name1(self, **kwargs):
    return self.run('name-1', kwargs)

def name2(self, ** kwargs):
    return self.run('name-2', kwargs)

So on and so forth.

There is a run function that takes care of the real work.

I want to reduce the 200 stub function to just 1 dynamic function that gets called when you make a call to the class with a method name that doesn't exist.

How do I do this?


Aucun commentaire:

Enregistrer un commentaire