update attribute - (newbie)

Bruce epost2 at gmail.com
Tue Dec 19 09:33:20 EST 2006


>>> class A:
...  def __init__(self):
...   self.t = 4
...   self.p = self._get_p()
...  def _get_p(self):
...   return self.t
...
>>> a = A()
>>> a.p
4
>>> a.t += 7
>>> a.p
4

I would like to have it that when I ask for p, method _get_p is always
called so that attribute can be updated. How can I have this
functionality here? thanks




More information about the Python-list mailing list