so its valid python code to write the expression

innerDict['+newinnrkey+'] 

without enclosing the parts outside of the plus-signs surrounding the 
"newinnrkey" variable within quotes or double quotes?
I'm not sure I've ever heard or seen such python code before anywhere.
Can you explain or point me to some docs on this type of code expression?
And are there any gotchas or problems coding expressions like this?
Thanks for the help.

Henry 
 

On Tuesday, March 10, 2015 at 4:34:34 PM UTC-5, ke1g wrote:

> eval() operates on an expression, not a statement.  Assignment makes it a 
> statement.
>
> Why wouldn't you just say:
>
>   innerDict['+newinnrkey+'] = newinnrval
>
>
> On Tue, Mar 10, 2015 at 5:25 PM, Henry Versemann <fence...@gmail.com 
> <javascript:>> wrote:
>
>> I have a new dictionary that I want to build, using data from another 
>> dictionary. I have a view which is receiving a single key/value pair 
>> from the original dictionary. Then in the view I've defined the new 
>> dictionary like this:
>>
>> innerDict = {}  
>>
>> Now I want to make this as dynamic as possible so I'm trying to use the 
>> "eval()" statement below to add the new key/value pair to the new 
>> dictionary, which is declared above. Will the following code work to 
>> actually add the new key/value pair to the new dictionary?
>>
>> innrDictCmnd = "innerDict['"+newinnrkey+"'] = newinnrval"
>> eval(innrDictCmnd)
>>
>> If not why not, and in lieu of the statements above not working, then how 
>> would I do it?
>>
>> Thanks for the help.
>>
>> Henry
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/e6c61ca1-efba-4965-a5ec-f10b55927b15%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/e6c61ca1-efba-4965-a5ec-f10b55927b15%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a6113acb-e437-42c6-88d9-f19476905dbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to