assignment to reference

Michael Tobis mtobis at gmail.com
Wed Oct 26 17:56:56 EDT 2005


I apparently don't understand this question in the same way the way
others do. I think the question is about the mutability of strings.

To my understanding of your question, it is impossible, at least if the
referenced objects are strings or other objects of immutable type.

 'cabbage' cannot be changed into 'coconut', though list('cabbage') can
be changed to list('coconut') in place.

>>> x = list('cabbage')
>>> id(x)
458640
>>> y = list('coconut')
>>> id(y)
458736
>>> x[:] = y[:]
>>> x
['c', 'o', 'c', 'o', 'n', 'u', 't']
>>> id (x)
458640
>>> "".join(x)
'coconut'

You would need to be doing a LOT of these for any of this to be worth
the bother, or else have some rather exotic application you aren't
telling us about.

If I am reading you right the eval() is a red herring. I agree with the
others that you don't want an eval() here and you're better off with a
dict, but I am not sure that answers your question. 

mt




More information about the Python-list mailing list