Created
June 26, 2012 13:54
-
-
Save Frost/2995906 to your computer and use it in GitHub Desktop.
method_missing in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MethodMissing(object): | |
| def method_missing(self, attr, *args, **kwargs): | |
| """Stub: override this function""" | |
| raise AttributeError("Missing method %s called." % attr) | |
| def __getattr__(self, attr): | |
| def callable(*args, **kwargs): | |
| return self.method_missing(attr, *args, **kwargs) | |
| return callable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment