Created
April 6, 2010 16:05
-
-
Save passy/357759 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
# -*- coding: utf-8 -*- | |
""" | |
Tests dynamic inheritence with python. | |
""" | |
class MixinA(object): | |
my_attr = 5 | |
def __init__(self): | |
print "hey, berry scott here!" | |
class MixinB(object): | |
def bark(self): | |
print("Bark, bark.") | |
class BaseClass(object): | |
my_attr = 1337 | |
def __init__(self): | |
super(BaseClass, self).__init__() | |
print("Hello there. My attr is {0}.".format(self.my_attr)) | |
if hasattr(self, 'bark'): | |
print("I haz bark.") | |
self.bark() | |
if __name__ == '__main__': | |
NewClass = type('NewClass', (BaseClass, MixinA, MixinB), {}) | |
b = NewClass() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment