[Tutor] Addressing a variable whose name is the value of a string
spelzdinkelclonk at web.de
Sun Apr 8 20:29:48 CEST 2007
Bob Gailer wrote:
> Andreas Pfrengle wrote:
>> I want to change the value of a variable whose name I don't know, but
>> this name is stored as a string in another variable, like:
>> x = 1
>> var = 'x'
>> Now I want to change the value of x, but address it via var.
> exec is the statement for doing this, but the need to do this can
> always be met better by using a dictionary instead of global variables.
Thanks Bob, the 'exec' saved me. But I'm not sure how I could solve my
specific problem with a dict, since my 'var' variable is a string I'm
getting from a database-field, that refers to the name of another field,
which should be changed. So I see no other way than resolving the string
in some instance - or is there?
More information about the Tutor