Properties vs. get/set-methods
Mark McEahern
marklists at mceahern.com
Thu Aug 22 08:33:52 EDT 2002
> When using properties, I can't use val to save the state.
> Accessing self.val would lead to infinite recursion here. So, if I
> want to save the state, I'd have to introduce another attribute.
The answer is embodied in this sample code:
class foo(object):
def __init__(self):
self._val = None
def setVal(self, val):
self._val = val
def getVal(self):
return self._val
val = property(getVal, setVal)
Where's the infinite recursion in this?
Cheers,
// m
-
More information about the Python-list
mailing list