Skip to content

Instantly share code, notes, and snippets.

@sonkm3
Created January 3, 2012 11:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sonkm3/1554556 to your computer and use it in GitHub Desktop.
Save sonkm3/1554556 to your computer and use it in GitHub Desktop.
python classmethod/staticmethod with inheritance
class Foo():
message = "I'm Foo class"
def method(self, foo):
self.foo = foo
print self.message
@classmethod
def class_method(cls, foo):
cls.foo = foo
print cls.message
@staticmethod
def static_method(foo):
Foo.foo = foo
print Foo.message
class Bar(Foo):
message = "I'm Bar class"
Foo.class_method(None)
# I'm Foo class
Foo.static_method(None)
# I'm Foo class
Bar.class_method(None)
# I'm Bar class
Bar.static_method(None)
# I'm Foo class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment