Skip to content

Instantly share code, notes, and snippets.

@capttwinky
Created January 22, 2015 22:32
Show Gist options
  • Save capttwinky/4362762b90977affb90f to your computer and use it in GitHub Desktop.
Save capttwinky/4362762b90977affb90f to your computer and use it in GitHub Desktop.
class InitAllMixin(object):
def __init__(self, *args, **kwargs):
for base in (c for c in self.__class__.__bases__ if c is not InitAllMixin):
base_class.__init__(self, *args, **kwargs)
class BaseClassOne(object):
spam_message = "class_spam"
def __init__(self):
self.spam_message = "instance_spam"
print "init BaseClassOne"
def do_spam(self):
print "did {}".format(self.spam_message)
class BaseClassTwo(object):
def __init__(self):
print "init BaseClassTwo"
class DerrivedOne(BaseClassTwo, BaseClassOne):
pass
class DerrivedTwo(InitAllMixin, BaseClassTwo, BaseClassOne):
pass
def main():
objOne = DerrivedOne()
print '*'*20
objTwo = DerrivedTwo()
print '*'*20
assert(dir(objOne) == dir(objTwo))
objOne.do_spam()
print '*'*20
objTwo.do_spam()
print '*'*20
return 0
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment