Last active
December 16, 2015 05:39
-
-
Save yuuichi-fujioka/5386129 to your computer and use it in GitHub Desktop.
クラスからメソッド取得
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 A: | |
def aaa(self): | |
''' instance method''' | |
print 'hello world' | |
@classmethod | |
def bbb(): | |
'''class method''' | |
print 'this is pen' | |
a = A() | |
aaa = getattr(a, 'aaa') | |
aaa() # hello world | |
aaa2 = getattr(A, 'aaa') | |
aaa2() # !ERROR | |
aaa2(a) # hello world | |
bbb = getattr(b, 'bbb') | |
bbb() # this is pen | |
bbb(b) # this is pen | |
bbb2 = getattr(B, 'bbb') | |
bbb2() # this is pen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment