[Tutor] indirect reference

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 6 Jun 2000 13:13:45 +0200


On Mon, Jun 05, 2000 at 03:45:22PM -0700, Sean 'Shaleh' Perry wrote:
> How do I:
> 
> foo = 'Hello'
> bar = foo
> 
> somehow change the value of foo via bar?

You can't, because strings are immutable. Put it in a class or so and give
the class a method to change its string. Then let foo and bar be the same
instance.

class ChangingString:
   def __init__(self, s):
      self.s = s

foo = ChangingString('Hello')
bar = foo
bar.s = 'Whee'
# foo.s == 'Whee' now

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl