<br><br><div class="gmail_quote">On Mon, Jan 12, 2009 at 7:24 AM, Heston James - Cold Beans <span dir="ltr"><<a href="mailto:heston.james@coldbeans.co.uk">heston.james@coldbeans.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div link="blue" vlink="purple" lang="EN-GB">

<div>

<p>Ok, this feels like a horribly noobish question to ask guys
but I can't figure this one out.</p>

<p> </p>

<p>I have code which looks like this:</p>

<p> </p>

<p style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;">           
</span><span style="font-size: 10pt; font-family: "Courier New"; color: blue;">print</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> this_config[</span><span style="font-size: 10pt; font-family: "Courier New"; color: maroon;">1</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;">]</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>


<p style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;">                       
</span><span style="font-size: 10pt; font-family: "Courier New";"></span></p>

<p><span style="font-size: 10pt; font-family: "Courier New"; color: black;">           
this_adapter_config[</span><i><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 170, 0);">"name"</span></i><span style="font-size: 10pt; font-family: "Courier New"; color: black;">] = this_config[</span><span style="font-size: 10pt; font-family: "Courier New"; color: maroon;">1</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;">][</span><i><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 170, 0);">"NAME"</span></i><span style="font-size: 10pt; font-family: "Courier New"; color: black;">]</span></p>


<p><span style="font-size: 10pt; font-family: "Courier New"; color: black;"> </span></p>

<p><span style="color: black;">Now, the print statement gives me
the following:</span></p>

<p> </p>

<p style="margin-left: 36pt; text-indent: 36pt;">{'value':
'Route66', 'key': 'NAME'}</p></div></div></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-GB">
<div><p style="margin-left: 36pt; text-indent: 36pt;"></p>

<p style="margin-left: 36pt; text-indent: 36pt;"> </p>

<p>Yet when the second line of my code throws an error saying
the key 'NAME' doesn't exist.</p>

<p> </p>

<p>Any ideas on what's going on, seems quite senseless to
me!?</p>

<p> </p>

<p>Thanks,</p>

<p> </p><font color="#888888">

<p>Heston</p>

</font></div>

</div>


</blockquote><div><br><br><br>
A dict stores key/value pairs. When you see the print of the
dict, it shows you {key1:value1, key2:value2}. So your dict has two
keys ('value' and 'key') that map to two values ('Route66' and 'Name' respectively). 'Name' is a value in the dict, not a key, so you can't use that syntax to get it.. In order for this code to work, the dictionary would have to be {'NAME' : 'Route66'} or you would have to use this_config[1]['value']<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br>