Skip to content

Instantly share code, notes, and snippets.

@thurloat
Forked from minichate/output
Created September 28, 2011 13:26
Show Gist options
  • Save thurloat/1247920 to your computer and use it in GitHub Desktop.
Save thurloat/1247920 to your computer and use it in GitHub Desktop.
Metaclasses
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
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