Skip to content

Instantly share code, notes, and snippets.

@paultag
Created October 15, 2014 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paultag/65e26a6e8c487b9a3915 to your computer and use it in GitHub Desktop.
Save paultag/65e26a6e8c487b9a3915 to your computer and use it in GitHub Desktop.
mro
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