Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.