Possible Duplicate:
How do I do variable variables in Python?
I have a variable with a string assigned to it and I want to define a new variable based on that string.
foo = "bar"
foo = "something else"
# What I actually want is:
bar = "something else"
exec
is becauselocals()
doesn't support modifications.locals()
doesn't support modifications because it would make the implementation more complex and slower and is never a good idea – John La Rooy Jul 19 '12 at 4:04