Created
January 3, 2012 11:27
-
-
Save sonkm3/1554556 to your computer and use it in GitHub Desktop.
python classmethod/staticmethod with inheritance
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 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