Newbie References Question -> Exemple

Guy Rabiller grabiller at 3dvf.net
Wed Sep 25 11:14:32 EDT 2002


Ok,

thanks for your answers, I understand now that a variable name is 'just' a
name in a dictionary, and not a container.

What I want to do is simple, and I suppose that this is my 'way of thinking'
regarding Python that is wrong.

I have a list of points, and a list of polygons that should contain
'references' to points.

So for me:
-> points list:
p = []
p.append([0,0])
p.append([0,1])
p.append([1,1])
p.append([1,0])
-> polygon:
quad = []
quad.append(p[0])
quad.append(p[1])
quad.append(p[2])
quad.append(p[3])

But now, if I change the coordinate of one point:
p[0] = [5,5]
I will have:
>>> p
[[5, 5], [0, 1], [1, 1], [1, 0]]
but:
>>> quad
[[0, 0], [0, 1], [1, 1], [1, 0]]

For me the quad list of point is not 'updated' with the change of one of its
point.

What I want to do is that, quad keeps a list of 'references' to points
coordinates.
Then if I change one point coordinates, the change is reflected in the quad
list of points.

I have no clue how to do this.

--
guy rabiller
3d animator / td
grabiller at 3dvf.net
http://grabiller.3dvf.net

Guy Rabiller wrote:
> Hi,
>
> let say I have:
> i1 = 1
> i2 = 2
> and
> p = [i1,i2]
>
> How can I have:
> p=[*i1,*i2]
> rather than
> p=[**i1,**i2] as it is curently ?
>
> ( Sorry for this nasty hybrid syntax )
>
> Textualy, how if I want that p[0] refere to the 'i1' container, and
> not to the refererence it contains ?
>
> What I want is that if now I set:
> i1 = 4
> that automaticaly:
> p -> [4,2]
> and not keeping [1,2]
>
> Thanks in advance.





More information about the Python-list mailing list