Last active
March 8, 2018 02:17
-
-
Save domodomodomo/191030f35cd3562cfb52b3b2249c460c to your computer and use it in GitHub Desktop.
This file contains 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
def classmethod(method): | |
def decorated_method(self, *args, **kwargs): | |
cls = type(self) | |
return method(cls, *args, **kwargs) | |
return decorated_method | |
def staticmethod(method): | |
def decorated_method(self, *args, **kwargs): | |
# self を省略してメソッドを呼び出す。 | |
return method(*args, **kwargs) | |
return decorated_method | |
class C(object): | |
# 第一引数を省略できる。 | |
@staticmethod | |
def stc_method(): | |
print('Hello, world!') | |
# 第一引数にクラスオブジェクトが代入される。 | |
@classmethod | |
def cls_method(cls): | |
print(cls.__name__) | |
o = C() | |
o.stc_method() | |
o.cls_method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment