Skip to content

Instantly share code, notes, and snippets.

@gtback
Last active August 29, 2015 14:12
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 gtback/650c4df9c4f54f852a65 to your computer and use it in GitHub Desktop.
Save gtback/650c4df9c4f54f852a65 to your computer and use it in GitHub Desktop.
Python Super types
class X(object):
@classmethod
def dostuff(cls, arg):
print "In X.dostuff: %s, %s" % (cls, arg)
class Y(X):
@classmethod
def dostuff(cls, arg):
print "In Y.dostuff: %s, %s" % (cls, arg)
super(Y, cls).dostuff(arg)
class Z(X):
@classmethod
def dostuff(cls, arg):
print "In Z.dostuff: %s, %s" % (cls, arg)
X.dostuff(arg)
>>> X.dostuff("fooX")
In X.dostuff: <class '__main__.X'>, fooX │
>>> Y.dostuff("fooY")
In Y.dostuff: <class '__main__.Y'>, fooY │
In X.dostuff: <class '__main__.Y'>, fooY
>>> Z.dostuff("fooZ")
In Z.dostuff: <class '__main__.Z'>, fooZ │
In X.dostuff: <class '__main__.X'>, fooZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment