Skip to content

Instantly share code, notes, and snippets.

@autf
Created March 10, 2022 02:05
Show Gist options
  • Save autf/43de0092e93b7433c4c90a4e2b36d632 to your computer and use it in GitHub Desktop.
Save autf/43de0092e93b7433c4c90a4e2b36d632 to your computer and use it in GitHub Desktop.
class T:
...
def _m(my): print('m', my)
T.m = _m
@classmethod
def _cm(cls): print('cm', cls)
T.cm = _cm
## ...OR
# def _cm(cls): print('cm', cls)
# T.cm = classmethod(cm)
def _sm(): print('sm')
T.sm = staticmethod(_sm)
# T.sm = _sm #=> Error!
t = T()
t.m()
T.m(t)
t.cm()
T.cm()
(T.cm)()
getattr(T, 'cm')()
t.sm()
T.sm()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment