pointer

Eric Brunel eric.brunel at pragmadev.com
Tue Apr 9 13:12:13 EDT 2002


Henning Peters wrote:
> is there anything similar to the pointer concept from c/c++ in python?
>
> i would like to store values in two different locations. both values
> should always be equal. the one could be a pointer on the other. is this
> possible to do this in python?

I'd use an attribute in an object. Try this:

class C:
  pass
o = C()
o.a = 'whatever'
oo = o
print oo.a
oo.a = 'yeah'
print oo.a
print o.a

You have two names ("o" and "oo") pointing on the same object, so changing 
the value of the attribute "a" on one changes the value on the other one.

HTH
 - eric -




More information about the Python-list mailing list