Jump to content


Photo

Error In High_score, Chapter 4


  • Please log in to reply
6 replies to this topic

#1 lualpo

lualpo

    New Member

  • Members
  • Pip
  • 1 posts

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.

#2 paulbarry

paulbarry

    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 306 posts

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.

#3 gpsxsirus

gpsxsirus

    New Member

  • Members
  • Pip
  • 5 posts

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


#4 gpsxsirus

gpsxsirus

    New Member

  • Members
  • Pip
  • 5 posts

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.

#5 gpsxsirus

gpsxsirus

    New Member

  • Members
  • Pip
  • 5 posts

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

#6 paulbarry

paulbarry

    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 306 posts

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....g/wiki/Notepad+

Regards.

--Paul.

#7 hmarro

hmarro

    New Member

  • Members
  • Pip
  • 5 posts

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users