O'Reilly Forums: Chapter 4 - , Line 4, In <module> Builtins.valueerror: Need More Than 0 Values To Unpack - O'Reilly Forums

Jump to content

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

Chapter 4 - , Line 4, In <module> Builtins.valueerror: Need More Than 0 Values To Unpack

#1 User is offline   stockita 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 09-March 14

Posted 09 March 2014 - 08:28 PM

Hello,

I wrote the code and down load the file results.txt they are in one directory... but return the error : , line 4, in <module>
builtins.ValueError: need more than 0 values to unpack

the code the i wrote:

highest_score = 0
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
if float(score) > highest_score:
highest_score = float(score)
result_f.close()
print('The highest score was:')
print(highest_score)
0

#2 User is offline   #TM# 

  • Active Member
  • PipPipPip
  • Group: Members
  • Posts: 63
  • Joined: 10-December 12
  • Gender:Not Telling

Posted 13 March 2014 - 02:56 AM


The code is perfectly fine if you have indented it properly.

Probably the problem is while copying the "results.txt" file content ( or after downloading the "results.txt" file, you opened it and messed up a little bit ;) :P ); you left a blank line at the top of the file. That's why the split() method is not able to unpack anything. i.e., 0 values to unpack.

highest_score = 0
result_f = open("results.txt")
for line in result_f:
    (name, score) = line.split() # Problem is here line no. 4; the built-in method split get no value to unpack so ValueError.
    if float(score) > highest_score:
        highest_score = float(score)
result_f.close()
print('The highest score was:')
print(highest_score) 


Try opening the file and clear any blank lines at the top.
:rolleyes: B)


This post has been edited by #TM#: 13 March 2014 - 02:58 AM

0

#3 User is offline   stockita 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 09-March 14

Posted 18 March 2014 - 03:47 AM

thanks,
right, actually the code is indented, im using Komodo and wings, however that wasn't the case.
you were right, i did re write the result.txt file my self, and it works now.

thanks again.



View Post#TM#, on 13 March 2014 - 02:56 AM, said:


The code is perfectly fine if you have indented it properly.

Probably the problem is while copying the "results.txt" file content ( or after downloading the "results.txt" file, you opened it and messed up a little bit ;) :P ); you left a blank line at the top of the file. That's why the split() method is not able to unpack anything. i.e., 0 values to unpack.

highest_score = 0
result_f = open("results.txt")
for line in result_f:
    (name, score) = line.split() # Problem is here line no. 4; the built-in method split get no value to unpack so ValueError.
    if float(score) > highest_score:
        highest_score = float(score)
result_f.close()
print('The highest score was:')
print(highest_score) 


Try opening the file and clear any blank lines at the top.
:rolleyes: B)



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