O'Reilly Forums: Error In High_score, Chapter 4 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Error In High_score, Chapter 4

#1 User is offline   lualpo 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 07-March 10

Posted 07 March 2010 - 04:15 PM

Hello, great book so far.

Received the following error when attempting to execute the high-score program in Chapter 4:

Traceback (most recent call last):
File "C:\Documents and Settings\Luis Porrello\My Documents\My Python\Head_First_Programming\high_score.py", line 4, in <module>
(name, score) = line.split()
ValueError: need more than 0 values to unpack

I have tried using the version of the code provided on the website for page 140 but received the same error. Is there anything I need to do to the "results.txt" file? When I open it is not ordered in columns but rather one single line.

Thanks in advance.
0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 08 March 2010 - 08:43 AM

QUOTE (lualpo @ Mar 7 2010, 04:15 PM) <{POST_SNAPBACK}>
I have tried using the version of the code provided on the website for page 140 but received the same error. Is there anything I need to do to the "results.txt" file? When I open it is not ordered in columns but rather one single line.


The only requirement is that the file needs to be in the same directory as the program.

Here's what the contents of the file should look like (i.e., not all on one line):

Johnny 8.65
Juan 9.12
Joseph 8.45
Stacey 7.81
Aideen 8.05
Zack 7.21
Aaron 8.31

Hope this helps.

Paul.
0

#3 User is offline   gpsxsirus 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 13-April 10

Posted 29 April 2010 - 02:26 AM

I'm getting the exact same error:
Traceback (most recent call last):
File "C:\Users\Justin\Documents\Study Materials\Python Projects\page140.py", line 4, in <module>
(name, score) = line.split()
ValueError: need more than 0 values to unpack

I first was getting it when I modified the code to match what is on page 124/125. Then I downloaded the example from the site (matches the code on page 140/141) and I still get the exact same error.

The text document as I downloaded it was all one line, I edited it so each surfer and their score had their own line.

Windows 7 x64 build 7600
IDLE x64 version 3.1.2
Python version 3.1.2 Tk version 8.5

0

#4 User is offline   gpsxsirus 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 13-April 10

Posted 29 April 2010 - 02:29 AM

I thought maybe it was a Win7 security issue. Just ran IDLE as administrator and got the same error.
0

#5 User is offline   gpsxsirus 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 13-April 10

Posted 04 May 2010 - 09:51 AM

I figured out what my problem was. It wasn't anything with my code or with IDLE; and the original text file was fine.

The problem is with the latest version of Notepad of all things. For some reason it wasn't showing the line breaks that ARE present in the file. I emailed the file to myself in Gmail then loaded in Google Docs and it displays just fine.

I've heard that MS has been adding XML features to Notepad. Way to take one of the most reliable programs in existence and make it unusable.

Good news is my coding and the book examples are just fine!! smile.gif
0

#6 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 05 May 2010 - 12:50 AM

QUOTE (gpsxsirus @ May 4 2010, 09:51 AM) <{POST_SNAPBACK}>
Good news is my coding and the book examples are just fine!! smile.gif


That is good news, because I was completely at a loss to suggest anything else. You may want to look at NotePad+ which a lot of my students use in place of Notepad on Windows. They quite like it.

http://en.wikipedia.org/wiki/Notepad%2B

Regards.

--Paul.
0

#7 User is offline   hmarro 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 04-July 12

Posted 18 July 2012 - 10:44 PM

I solved the problem by using a different text editor. I'm a user of Ubuntu, and the very first time I created the text file with Gedit and I got the same error message.

Use a different text editor for creating the "results.txt" file and will run OK.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users