Last active
November 10, 2015 18:38
-
-
Save rbpasker/94117454a1c0a15dca1c to your computer and use it in GitHub Desktop.
This file contains 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 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') |
This file contains 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
$ 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