Created
January 22, 2015 22:32
-
-
Save capttwinky/4362762b90977affb90f 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 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