Skip to content

Instantly share code, notes, and snippets.

@mirekfranc
Created May 8, 2015 21:57
Show Gist options
  • Save mirekfranc/18f1117e26a405bf2d2a to your computer and use it in GitHub Desktop.
Save mirekfranc/18f1117e26a405bf2d2a to your computer and use it in GitHub Desktop.
python class with an attribute that no longer exists...
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