Objects with different data views

D.Hering vel.accel at gmail.com
Fri Oct 7 20:37:29 CEST 2005


Paul Rubin wrote:
> Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
>
> class Parrot(object):
>   x = property(getx, setx)
>   y = property(gety, sety)
>
>   def getx(self):
>      return self.a + self.b
>   def setx(self, x):
>      y = self.y   # calls gety
>      self.a, self.b = 2*x - y, y-x
>
>   def gety(self):
>      return self.a + 2*self.b
>   def sety(self, y):
>      x = self.x    # calls getx
>      self.a, self.b = 2*x - y, y-x

 class Parrot(object):

   def getx(self):
      return self.a + self.b
   def setx(self, x):
      y = self.y   # calls gety
      self.a, self.b = 2*x - y, y-x

   def gety(self):
      return self.a + 2*self.b
   def sety(self, y):
      x = self.x    # calls getx
      self.a, self.b = 2*x - y, y-x

   x = property(getx, setx)
   y = property(gety, sety)




More information about the Python-list mailing list