Skip to content

Instantly share code, notes, and snippets.

@domodomodomo
Last active March 8, 2018 02:17
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 domodomodomo/191030f35cd3562cfb52b3b2249c460c to your computer and use it in GitHub Desktop.
Save domodomodomo/191030f35cd3562cfb52b3b2249c460c to your computer and use it in GitHub Desktop.
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