Skip to content

Instantly share code, notes, and snippets.

@bhumpert
Created June 2, 2017 17:33
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 bhumpert/6586ef08d48d341fac10a803d10bc88c to your computer and use it in GitHub Desktop.
Save bhumpert/6586ef08d48d341fac10a803d10bc88c to your computer and use it in GitHub Desktop.
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