[Tutor] KeyError?

James Reynolds eire1130 at gmail.com
Thu Jul 28 17:59:28 CEST 2011


On Thu, Jul 28, 2011 at 11:50 AM, Shwinn Ricci <armvrt at 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?
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Did you try printing the contents of scafPositions to see what it contains,
first?

Also, a traceback is helpful.

As far as introspection, which module are you using to read the excel files?
There's at least two that I know of.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110728/3c7820fb/attachment.html>


More information about the Tutor mailing list