Properties vs. get/set-methods

Michael 'Mickey' Lauer mickey at
Thu Aug 22 20:06:07 EDT 2002

Mark McEahern <marklists at> wrote:
>> 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?

Hmm... sure, I already stated that involving a second attribute
is needed to save state. My original question about the real
usage scenario for properties remains though.


More information about the Python-list mailing list