Kent Johnson wrote:
> Andreas Pfrengle wrote:
>
>> # Accessing db (see http://www.djangoproject.com/documentation/db-api/):
>> myobj = MyModel.objects.get()
>> var = myobj.vector
>> # vector is a Textfield, so var now contains a string, naming another
>> db-field of myobj
>>
>> execstr = "attr =
Andreas Pfrengle wrote:
> # Accessing db (see http://www.djangoproject.com/documentation/db-api/):
> myobj = MyModel.objects.get()
> var = myobj.vector
> # vector is a Textfield, so var now contains a string, naming another
> db-field of myobj
>
> execstr = "attr = myobj." + var
> exec execstr
>
Bob Gailer wrote:
> Andreas Pfrengle wrote:
>
>> [snip]
>
>> looks good if I'm happy with my values inside mydict and don't want
>> to have sth. like x=5 in the end. But since 'x' is the name of a
>> database field (I simplified it here for an example), I still see no
>> way around the exec, so
Andreas Pfrengle wrote:
> Bob Gailer wrote:
>
>> Andreas Pfrengle wrote:
>>
>>> Hello,
>>>
>>> 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
John Clark wrote:
> locals()[var]
>
> But I am not sure what the pros/cons for doing something like this would
> be...
locals() should be considered read-only. From the docs:
locals( )
Update and return a dictionary representing the current local
symbol table. Warning: The content
Andreas Pfrengle wrote:
> Bob Gailer wrote:
>>> 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
Andreas Pfrengle wrote:
> [snip]
> looks good if I'm happy with my values inside mydict and don't want to
> have sth. like x=5 in the end. But since 'x' is the name of a database
> field (I simplified it here for an example), I still see no way around
> the exec, so I can change the content of
Jordan Greenberg wrote:
Andreas Pfrengle wrote:
Bob Gailer wrote:
Andreas Pfrengle wrote:
Hello,
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
Bob Gailer wrote:
> Andreas Pfrengle wrote:
>
>> Hello,
>>
>> 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
Bob Gailer wrote:
>Andreas Pfrengle wrote:
>> Hello,
>>
>> 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
Andreas Pfrengle wrote:
> Hello,
>
> 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 t
Hello,
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. I'm quite
sure I've already seen a solution for this, but right now I don't get it
12 matches
Mail list logo