sbowde4 sbowde4 - 1 year ago 114
Python Question

Input string error EOF

I am making a program to demo different types of graphs using matplotlib, and I am having an issue with user input.

My program has been working since I created it, but when I ran it today upon start up I am getting an error and I just cannot figure out why.

Here is the code that is throwing the error

if options == 0:
fileX = input("Enter the file of x coordinates > ")
fileY = input("Enter the file of y coordinates > ")
title = input("Enter title for the graph > ")
xlabel = input("Enter a name for the x-axis > ")
ylabel = input("Enter a name for the y-axis > ")
g.linegraph(title, xlabel, ylabel, fileX, fileY)

here is the error (my files' names are 10int1, and 10int2)

Traceback (most recent call last):
File "/home/sam/Documents/GraphDemo/src/", line 25, in <module>
fileX = input("Enter the file of x coordinates > ")
File "<string>", line 1
SyntaxError: unexpected EOF while parsing

can someone help to explain why this error is being thrown? It has worked up until now. I've tried different files, and different ways to input but I get the same error every time.

Answer Source

Are you running Python 2.7?

If so, input attempts to evaluate the input as a Python expression. When you enter 10int1 as the input, it attempts to evaluate this as a string, which it isn't – there are no opening/closing quotes.

Instead, you should use raw_input, which simply returns a string (without attempting to evaluate). Then, you should convert that input to an integer or whatever type you require.