[Tutor] Trivia

Andre Engels andreengels at gmail.com
Fri Jun 24 09:13:02 CEST 2011


On Fri, Jun 24, 2011 at 8:56 AM, Vincent Balmori
<vincentbalmori at yahoo.com>wrote:

>
> <<<try:
>
> point = int(next_line(the_file))
>
> If x is a string that can be interpreted as an integer number, int(x) is
> that integer number; if the string is not the representation of an integer,
> this will lead to a ValueError.
>
> --
> André Engels, andreengels at gmail.com>>>
>
>
> It's working fine now with the scoring, but now at the end of the program
> for some reason I get this error message:
>
> Traceback (most recent call last):
>  File
>
> "/Users/vincentbalmori/Desktop/Python/py3e_source/chapter07/trivia_challenge2.py",
> line 83, in <module>
>    main()
>  File
>
> "/Users/vincentbalmori/Desktop/Python/py3e_source/chapter07/trivia_challenge2.py",
> line 76, in main
>    category, point, question, answers, correct, explanation =
> next_block(trivia_file)
>  File
>
> "/Users/vincentbalmori/Desktop/Python/py3e_source/chapter07/trivia_challenge2.py",
> line 27, in next_block
>     point = int(next_line(the_file))
> ValueError: invalid literal for int() with base 10: ''
>
>
The important thing in such a case is reading the error message and the last
line in the error trace. In this case the error message is:

ValueError: invalid literal for int() with base 10: ''

This means that the int() function is being called with something that is
not an integer - it even says what that something is, namely '' - that is,
the empty string. Apparently at some time you come to the line

point = int(next_line(the_file))

when next_line(the_file) is the empty string.

-- 
André Engels, andreengels at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110624/7ce3eac6/attachment-0001.html>


More information about the Tutor mailing list