Skip to content

Instantly share code, notes, and snippets.

@gobengo
Created November 12, 2010 19:12
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 gobengo/674526 to your computer and use it in GitHub Desktop.
Save gobengo/674526 to your computer and use it in GitHub Desktop.
>>> class X:
... pass
...
>>> @classmethod
... def mysum(cls, x, y):
... return x + y
...
>>> X.setattr('s', mysum)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class X has no attribute 'setattr'
>>> X.__dict__['s'] = mysum
>>> X.s(1,2)
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment