On 28 July 2011 16:50, Shwinn Ricci <arm...@gmail.com> wrote: > I have an excel file that I am reading cell values from and putting them > into a dictionary. the dictionary looks like this: > > scafPositions = {position[j]: direction[j]} > > where position[j] is exclusively floating/numerical values and direction[j] > is exclusively strings. > > When I try to find whether a test value val is in the array of positions, > and then try to look its direction up with ScafPositions[val], I get a > KeyError. Is this because my data isn't standalone numbers, but numbers that > are calculated based off other cells? Or can I not test for val? >
http://wiki.python.org/moin/KeyError I quote: "Python raises a *KeyError* whenever a dict() object is requested (using the format a = adict[key]) and the key is not in the dictionary. If you don't want to have an exception but would rather a default value used instead, you can use the get() method: " Walter
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor