indirect references

Trent Mick trentm at activestate.com
Mon Jun 5 19:09:15 EDT 2000


On Mon, Jun 05, 2000 at 10:36:40PM +0000, shaleh at debian.org wrote:
> How do I do this in python:
> 
> foo = 'string'
> bar = foo
> 
> somehow assign to bar and change the value of foo.
> 
> 
I don't think I am sticking my foot in my mouth: Strings are immutable in
Python and passed/assigned by value (not by reference, which is what you are
asking for here). Arrays and dictionaries are passed by reference. Maybe you
could setup you data to use an array, pass a reference to it and change its
value, like this:

>>> foo = ['string']
>>> bar = foo
>>> bar[0] = 'hello'
>>> foo
['hello']
>>> bar
['hello']
						


Trent


-- 
Trent Mick
trentm at activestate.com




More information about the Python-list mailing list