Skip to content

Instantly share code, notes, and snippets.

@passy
Created April 6, 2010 16:05
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 passy/357759 to your computer and use it in GitHub Desktop.
Save passy/357759 to your computer and use it in GitHub Desktop.
# -*- 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