Re: Objects with different data views

2005-10-07 Thread George Sakkis
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > I'm not sure how to do this, or where to start looking for the right > information, so any advice would be appreciated. > > I want to implement a class with two (or more) different ways of looking > at its attributes. > > One example of this might be

Re: Objects with different data views

2005-10-07 Thread Paul Rubin
Yeah, that's what I meant. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Objects with different data views

2005-10-07 Thread D.Hering
Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> 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 > >

Re: Objects with different data views

2005-10-07 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Anyone have any good ideas for how I should implement this? These days you can use properties. Before, you'd have had to do it manually with __setattr__ / __getattr__ methods. Here's how I'd do it with properties, if I have the math right. You're us

Re: Objects with different data views

2005-10-07 Thread Fredrik Lundh
Steven D'Aprano wrote: > It is important that there are no privileged attributes, e.g. in the > above example, I can set any of x, y, z, r, theta or phi and all the > others will automatically reflect the changes. http://users.rcn.com/python/download/Descriptor.htm#properties -- http://mail

Objects with different data views

2005-10-07 Thread Steven D'Aprano
I'm not sure how to do this, or where to start looking for the right information, so any advice would be appreciated. I want to implement a class with two (or more) different ways of looking at its attributes. One example of this might be complex numbers, which can be written in Cartesian form (x