Jump to content


Photo

Chapter 11 - Marathon.py Keyerror


  • Please log in to reply
2 replies to this topic

#1 emtshea

emtshea

    New Member

  • Members
  • Pip
  • 2 posts
  • Gender:Male

Posted 17 January 2011 - 01:37 PM

I've been struggling with a KeyError while working with the code on page 403. As soon as I run it, I get the error. It stops in the num_2mi module:

...marathon.py", line 17, in <module> num_2mi = len(row_data['2mi'])


CODE
num_2mi = len(row_data['2mi'])
print(num_2mi, end=' -> ')
print(row_data['2mi'])


As the first module (num_cols) executes without error and prints to the console, I'm thinking it has something to do with the data type?

I'm stuck.

#2 paulbarry

paulbarry

    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 307 posts

Posted 18 January 2011 - 02:42 AM

I've downloaded the code for page 404 from here: http://www.headfirst...e/chapter11.zip and it works fine for me. Perhaps it might be a good idea to download the book's code and compare it to yours? The problem may not be with the lines of code that you are showing... it may be earlier in the code, perhaps?

Paul.

#3 emtshea

emtshea

    New Member

  • Members
  • Pip
  • 2 posts
  • Gender:Male

Posted 19 January 2011 - 11:48 AM

A friend introduced me to Notepad++ and its Compare plugin. Apparantly, I can't tell the difference between a zero and the letter "O". blink.gif

At any rate, the fact that I had the letter "O" in the following line, was the cause of my dilema:

CODE
row_label = row.pop(0)


Anyway, thanks for the help Paul.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users