Created
June 2, 2017 17:33
-
-
Save bhumpert/6586ef08d48d341fac10a803d10bc88c 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
In [31]: class A(object): | |
...: @classmethod | |
...: def show(cls, x): | |
...: print(x) | |
...: | |
In [32]: a = A() | |
In [33]: A.show(1) | |
1 | |
In [34]: a.show(1) | |
1 | |
In [35]: import types | |
In [36]: def newshow(cls, x): | |
...: print("You passed {}".format(x)) | |
...: | |
In [37]: a.show = types.MethodType(newshow, A) # 2nd param class -> classmethod! | |
In [38]: A.show(1) | |
1 | |
In [39]: a.show(1) | |
You passed 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment