Using pointers

Chris Liechti cliechti at gmx.net
Sat Jul 20 10:26:24 EDT 2002


jkrahn at nc.rr.com (Joe Krahn) wrote in 
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.

see the other post from Gonçalo.

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

you can store the variable in an other object. a class is such a thing or 
you can use a list:

a = [0]
b = a

now b and a reference the same list adn you can get the first object of 
that list with a[0] or b[0] if you want to change it just say a[0] = 3 etc.

a class is much nicer for such things. you maybe want to look at object 
oriented programming in general.

class Storage:
    	def __init__(self, value):
    	    	self.value = value

a = b = Storage(7)
print a.value
print b.value
a.value = 5
print b.value

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list