hi Scott,
Scott David Daniels wrote:
Esmail wrote:
I am just reading about properties in Python. I am thinking
of this as an indirection mechanism, is that wrong? If so, how
come the getter/setters aren't called when I use properties
instead of the functions directly?
Because you weren't actually using them. You were writing:
size = 3, 7
not:
r.size = 3, 7
duh!! .. I knew it had to be something sill .. how do I represent
a red face in ASCII ? ;) I was concentrating so much on the new
feature I totally didn't see this.
I appreciate your code with annotations, helpful.
def setSize(self, shape): # a setter takes a single arg
width, height = shape
print 'in setter'
if width < 0 or height < 0:
print >> sys.stderr, 'Negative values not allowed'
else:
self._width = width
self._height = height
r.setSize((-40, 30))
Just curious, is there a way to pass more than one arg to a setter, or
do we always have use some sort of unpacking at the other end?
Thanks,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list