Created
November 12, 2010 19:12
-
-
Save gobengo/674526 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 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