[Tutor] Do not understand why I am getting "EOFError: EOF when reading a line".
boB Stepp
robertvstepp at gmail.com
Sat Oct 8 00:51:56 EDT 2016
I think I now understand why I am getting this EOF exception.
On Fri, Oct 7, 2016 at 10:16 PM, boB Stepp <robertvstepp at gmail.com> wrote:
> My current get_input() function:
>
> ======================================================
> def get_input():
> '''Get string input from the user and convert it to an integer. This
> integer is returned to the caller.
>
> :num_sides: Number of sides for the displayed grid.'''
>
> while True:
> try:
> num_sides = int(input("Number of sides = "))
> return num_sides
> except ValueError:
> print("'Number of sides' must be a positive integer. Please enter "
> "an integer.")
> =======================================================
Since the try/except is within a while loop, the input tries to read
more input after the ValueError occurs. Of course, I don't have any
more input strings stored in the StringIO buffer, so it sees this as
an end of file condition.
But now I do not see how to test get_input() to check for the
ValueError. Any suggestions?
boB
More information about the Tutor
mailing list