Skip to content

Instantly share code, notes, and snippets.

@rbpasker
Last active November 10, 2015 18:38
Show Gist options
  • Save rbpasker/94117454a1c0a15dca1c to your computer and use it in GitHub Desktop.
Save rbpasker/94117454a1c0a15dca1c to your computer and use it in GitHub Desktop.
class Foo(object):
def a(*args):
return 'a', args
def b(*args):
return 'b', args
def __init__(self):
self.which = {'A' : self.a, 'B' : self.b}
def _default(self, key):
f = self.which[key]
return f(key)
def __getattr__(self, missing_attribute):
return self._default
foo = Foo()
print foo.abc('A')
$ python scratch/ga.py
('a', (<__main__.Foo object at 0x104098790>, 'A'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment