1

I have a very basic program that takes user input and reads it back to the user. the code is:

x = input("hello what is your name: ") print("hello " + x) 

This works perfectly when run in idle however when run I run it by clicking on the file to get the command line type interface when I enter input i get the following error message:

 File "C:\Users\ROB\Desktop\test.py", line 1, in (module) x = input("hello what is your name: ") File "(string)", line 0 ^ SyntaxError: unexpected EOF while parsing 

can someone pleese explain why this happens and suggest a solution to enable me to take user input in the command line.

2 Answers 2

2

You are using Python 2, and are executing this somewhere with stdin closed:

>>> x = input("hello what is your name: ") hello what is your name: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing 

On Python 2, use raw_input() instead, and run this in a terminal or Windows console, or from within IDLE.

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

1 Comment

Martijn thank you for a quick answer.your comment about me running python two made me relise that my proggrame was opening with the wrong launcher as i had python 2 updated to python 3 but did not delete python 2 meaning my code was running under python 2 even though i thought it was running under python 3
1

See also

Python unexpected EOF while parsing

from the python docs (http://docs.python.org/2/library/functions.html#input):

input([prompt]):
Equivalent to eval(raw_input(prompt)).
This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

Consider using the raw_input() function for general input from users.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.