1

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/GraphDemo.py", line 25, in <module>
    fileX = input("Enter the file of x coordinates > ")
  File "<string>", line 1
    10int1
         ^
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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked, but then I got another error because I removed self from def linegraph(self, title, xlabel, ylabel, fileX, fileY): then it stopped working again when I readded self to fix the error
Nevermind the above comment. I just cleaned the code and it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.