Is it possible to implement generic method handlers in python which allow for calling of non-existent functions? Something like this:
class FooBar:
def __generic__method__handler__(.., methodName, ..):
print methodName
fb = FooBar()
fb.helloThere()
-- output --
helloThere
The first thing to remember is that methods are attributes which happen to be callable.
So you can handle non-existent methods in the same way you would handle non-existent attributes.
This is usally done by defining a
__getattr__method.Now you’re going hit the additional complexity which is the difference between functions and method. Methods need to be bound to an object. You can take a look at this question for a discussion of this.
So I think you’ll want something like this:
Which gives:
However, I’d probably recommend against using this. If you tell us the problem you’re trying to solve I expect someone here can come up with a better solution.