Created
May 8, 2015 21:57
-
-
Save mirekfranc/18f1117e26a405bf2d2a to your computer and use it in GitHub Desktop.
python class with an attribute that no longer exists...
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
class Nonsense(object): | |
def __init__(self, n): | |
self.a = ['x'] * n | |
@property | |
def length(self): | |
return len(self.a) | |
@length.setter | |
def length(self, n): | |
self.a = ['x'] * n | |
def __str__(self): | |
return "|".join(self.a) | |
x = Nonsense(5) | |
print x | |
print x.length | |
x.length = 8 | |
print x | |
print x.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment