Loris Caren wrote: > a = 'apple' > b = 'banana' > c = 'cabbage' > > How can I get something like:- > > for i in 'abc': > r = eval(i) > if r == 'cabbage': r = 'coconut' > > actually change the object referenced by r rather > than creating a new object temporarily referenced by it?
if you need a container, you should use a container object instead of the local namespace. in this case, a dictionary is what you want: stuff = { 'a': 'apple', 'b': 'banana', 'c': 'cabbage' } for i in "abc": if stuff[i] == "cabbage": stuff[i] = "coconut" (tweak as necessary) </F> -- http://mail.python.org/mailman/listinfo/python-list