Created
October 20, 2011 18:00
-
-
Save nkuln/1301815 to your computer and use it in GitHub Desktop.
Playing with Mixin which is basically a multiple inheritance. I was confused before on what the line 'cls = TestMixin' does ..
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 TestMixin(object): | |
member1 = ['gant','from','mixin'] | |
def mixin_method(self): | |
print 'member 1 from self: %s' % self.member1 | |
cls = TestMixin | |
print 'member 1 from cls: %s' % cls.member1 | |
class Cat(TestMixin): | |
member1 = 'meow meow' | |
def bark(self): | |
print 'I bark %s' % self.member1 | |
if __name__ == '__main__': | |
a = Cat() | |
a.bark() | |
a.mixin_method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment