[Tutor] Need help with find error

Danny Yoo dyoo at hashcollision.org
Wed Feb 4 19:12:58 CET 2015


On Wed, Feb 4, 2015 at 1:01 AM, Андрей Пугачев
<pugachov.andrey at gmail.com> wrote:
> Hi
> I'm learning python a few weeks and have problems with code that read text
> from txt-file
> Code doing all right, but in the end I have error
>
> Traceback (most recent call last):
>   File "trivia_challenge.py", line 81, in <module>
>     main()
>   File "trivia_challenge.py", line 74, in main
>     category, question, answers, correct, explanation, points =
> next_block(trivia_file)
>   File "trivia_challenge.py", line 37, in next_block
>     points = int(next_line(the_file))
> ValueError: invalid literal for int() with base 10: ''



Your next_line() function looks a little off.  Let's take a look at it:

############################################
def next_line(the_file):
    """Return next line from the trivia file, formatted."""
    line = the_file.readline()
    line = line.replace("/", "\n")
    return line
############################################

What do you want to happen here, when there are no more lines in the
file to read?


More information about the Tutor mailing list