Newbie References Question -> Exemple

Guy Rabiller grabiller at 3dvf.net
Wed Sep 25 11:35:16 EDT 2002


Ok I solved it, thanks to sismex.

If I want to change a coordinate, I have yo write:

p[0][:] = [5,5]

and not

p[0] = [5,5]

I understand that in the first case, the reference pointed ( via
dictionary ) by p[0] is lost, a new value is created and rebinded to p[0],
so quad and p[0] are not synchonised anymore.

In the second case, the reference pointed by p[0] is updated with a new
value. p[0] and quad are still synchronised.

Is my understanding correct ?

Thanks a lot to all.

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

Guy Rabiller wrote:
> 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 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