Metaclasses
This file contains hidden or 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 M(object): | |
def __init__(self, *args, **kwargs): | |
super(M, self).__init__() | |
setattr(self, "foo", self.baz) | |
setattr(self, "other_long_name", self.baz) | |
setattr(self, "metatastic", True) | |
@classmethod | |
def baz(cls): | |
return "FooBaz -- Base class %s" % cls | |
class B(M): | |
def __init__(self): | |
super(B, self).__init__() | |
def bar(self): | |
return "Bar" | |
b = B() | |
print b.bar() | |
print b.foo() | |
print b.other_long_name() | |
print b.metatastic | |
This file contains hidden or 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
Bar | |
FooBaz -- Base class <class '__main__.B'> | |
FooBaz -- Base class <class '__main__.B'> | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment