Newbie References Question

Terry Reedy tjreedy at udel.edu
Wed Sep 25 10:51:35 EDT 2002


"Guy Rabiller" <grabiller at 3dvf.net> wrote in message
news:3d91c72f$0$8558$79c14f64 at nan-newsreader-02.noos.net...

> 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 ?

Names, in themselves, are not Python objects and are certainly *not*
containers.  Once turned into Python string objects, they may be
contained within a dictionary and as key, associated with a reference.
But they still do not *contain* the reference; the dictionary, not the
name, is the container.

As a side note but still relevant: as a optimization in CPython at
least, local names within a function that are not used within nested
scopes are turned into array indexes.  They may be tossed after
compilation since they serve no further purpose.

> What I want is that if now I set:
> i1 = 4
> that automaticaly:
> p -> [4,2]
> and not keeping [1,2]

Too bad, since, it should not be clearer, this is not possible.  The
assignment means: associate 'i1' with [int object with value] 4 after
removing any previous association.

Terry J. Reedy





More information about the Python-list mailing list