Created
October 15, 2014 00:12
-
-
Save paultag/65e26a6e8c487b9a3915 to your computer and use it in GitHub Desktop.
mro
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
from collections import ChainMap | |
class Bar(object): | |
y = 1 | |
class Foo(Bar): | |
a = 1 | |
b = 2 | |
c = 3 | |
foo = 1 | |
bar = 2 | |
template = "{a} {b} {c} {y}" | |
def crawl(self): | |
return ChainMap(self.__dict__, *(x.__dict__ for x in type(self).mro())) | |
def hello(self): | |
return self.template.format(**self.crawl()) | |
x = Foo() | |
print(x.hello()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment