Newbie References Question

Harvey Thomas hst at empolis.co.uk
Wed Sep 25 10:52:48 EDT 2002


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.
> 
> --
> guy rabiller
> 3d animator / td
> grabiller at 3dvf.net
> http://grabiller.3dvf.net
> 
Well it is just about possible, but its an ugly hack.

Basically, all the members of the list p will need to be mutable - in practice each will need to be a list.

So:

>>> i1 = [1]
>>> i2 = [2]
>>> p = [i1, i2]
>>> i1[0] = 3
>>> p
[[3], [2]]
>>> i2[0] = 4
>>> p
[[3], [4]]

But I think it would be better if you told us what your real problem was so we could se if we could formulate a solution in a different way.

Harvey

_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.




More information about the Python-list mailing list