Using pointers

Terry Reedy tjreedy at udel.edu
Sat Jul 20 11:55:26 EDT 2002


"Joe Krahn" <jkrahn at nc.rr.com> wrote in message
news:4210d7a2.0207200538.44a91c0f at posting.google.com...
> Can I make a pointer to an object in Python? I know that all
> objects/variables are references, but not in the same sense as in C.

Let's reword a bit better.  Objects are objects and *not* references.
Variables are names associated with objects via internal references.

> How do I get multiple pointers to reference and modify one variable?

You mean like

a = ['test']
b = a
b[0] = 'done'
print a

?
This prints 'done', but this scheme only works with mutable objects.

Terry J. Reedy

PS.  CPython uses the id of an object as its internal reference, but
when you retrieve the id with the id() function, it becomes an
external int object and useless for accessing the object (unless you
subvert the interpreter by writing a custom C extension to do so).






More information about the Python-list mailing list