Posted on 2008-08-16 07:44:30
Here is a hacked up attempt of accomplishing Ruby's method missing in Python. While this is not as robust, it does manage to meet my needs.
class Thing(object):
def __init__(self):
self.__missing_method_name = None # Hack!
def __getattribute__(self, name):
return object.__getattribute__(self, name)
def __getattr__(self, name):
self.__missing_method_name = name # Could also be a property
return getattr(self, '__methodmissing__')
def __methodmissing__(self, *args, **kwargs):
print "Missing method %s called (args = %s) and (kwargs = %s)" % (self.__missing_method_name, str(args), str(kwargs))
t = Thing()
t.badness(123, 'an arg', blah="another argument here", zesty="woot")
Art
ColdFusion
Data Visualizations
Design
Inspiration
JavaScript
Life
Python
Ruby
Snippets
Content by Kunal Anand. Connect with me on Twitter, Facebook, or email.