Re: [Tutor] list of references to object properties

2013-01-19 Thread Oscar Benjamin
On 19 January 2013 15:47, Jose Amoreira wrote: > Thanks for the explanation, Alan > >> Is there a good reason to want to do such a thing? > > There is a reason, but maybe you won't consider it a good one... > > I was writing a small program to simulate the gravitational dynamics of a > system of m

Re: [Tutor] list of references to object properties

2013-01-19 Thread eryksun
On Sat, Jan 19, 2013 at 10:47 AM, Jose Amoreira wrote: > > I defined a class, CelestialBody, that describes objects that > represent planets in my simulation. These objects have three attributes: > position, velocity and mass (the first two are 3D-vectors; as such, the > number of attributes is ac

Re: [Tutor] list of references to object properties

2013-01-19 Thread DoanVietTrungAtGmail
Hi Jose, have you thought about shallow copying? I am learning Python too, so I can be wrong here. But I have just tried the idea and it worked for me: class celestialBody(object): def __init__(self, m, x, y, z): self.mass = m self.pos = [x, y, z] def __str__(self):

Re: [Tutor] list of references to object properties

2013-01-19 Thread Alan Gauld
On 19/01/13 15:47, Jose Amoreira wrote: motion. I defined a class, CelestialBody, that describes objects that represent planets in my simulation. These objects have three attributes: position, velocity and mass (the first two are 3D-vectors; as such, the number of attributes is actually 7). The

Re: [Tutor] list of references to object properties

2013-01-19 Thread Jose Amoreira
Thanks for the explanation, Alan > > Is there a good reason to want to do such a thing? There is a reason, but maybe you won't consider it a good one... I was writing a small program to simulate the gravitational dynamics of a system of many planets, using scipy's odeint to solve the equations

Re: [Tutor] list of references to object properties

2013-01-18 Thread Alan Gauld
On 18/01/13 11:11, Jose Amoreira wrote: Suppose I have a list l_obj of similar objects. Is there any way I can generate a list l_prp of references to a given property of those objects in such a way that, if change the value of one element in l_prp, the corresponding object in l_obj gets its prop

Re: [Tutor] list of references to object properties

2013-01-18 Thread Jose Amoreira
Thanks, Peter. I was trying to avoid the regenerate step for updating. But maybe I can restructure my code and objects to make this simpler. Before that I'll try this view approach. Thanks again Ze On Fri, Jan 18, 2013 at 11:37 AM, Peter Otten <__pete...@web.de> wrote: > Jose Amoreira wrote: > >

Re: [Tutor] list of references to object properties

2013-01-18 Thread Peter Otten
Jose Amoreira wrote: > Hello > Suppose I have a list l_obj of similar objects. Is there any way I can > generate a list l_prp of references to a given property of those objects > in such a way that, if change the value of one element in l_prp, the > corresponding object in l_obj gets its property