Created
November 8, 2012 17:36
-
-
Save rubensayshi/4040279 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
| import copy | |
| class MyClass(object): | |
| def __init__(self, x): | |
| self.x = x | |
| def __getattr__(self, name): | |
| if name == 'plus_one': | |
| newself = copy.copy(self) | |
| newself.x += 1 | |
| return newself | |
| a = MyClass(1) | |
| print a.x | |
| b = a.plus_one | |
| print b.x, a.x | |
| # | |
| # Traceback (most recent call last): | |
| # File "dev.py", line 16, in <module> | |
| # b = a.plus_one | |
| # File "dev.py", line 9, in __getattr__ | |
| # newself = copy.copy(self) | |
| # File "/usr/lib/python2.7/copy.py", line 88, in copy | |
| # rv = reductor(2) | |
| #TypeError: 'NoneType' object is not callable | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment