strange dict issue

Gary M. Josack gary at byoteki.com
Mon Jan 12 08:05:47 EST 2009


Heston James - Cold Beans wrote:
>
> Ok, this feels like a horribly noobish question to ask guys but I 
> can’t figure this one out.
>
> I have code which looks like this:
>
> print this_config[1]
>
> this_adapter_config[/"name"/] = this_config[1][/"NAME"/]
>
> Now, the print statement gives me the following:
>
> {'value': 'Route66', 'key': 'NAME'}
>
> Yet when the second line of my code throws an error saying the key 
> ‘NAME’ doesn’t exist.
>
> Any ideas on what’s going on, seems quite senseless to me!?
>
> Thanks,
>
> Heston
>
> ------------------------------------------------------------------------
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   

'NAME' is the value, and 'key' is the key. Your dictionary has two keys 
mapped to two values:

'value' -> 'Route66'
'key' -> 'NAME'


You need to lookup the values by their key. Does that make sense?

Thanks,
Gary M. Josack



More information about the Python-list mailing list