[Tutor] VERY basic question

Peter Otten __peter__ at web.de
Thu Oct 2 01:16:36 CEST 2014


Stefan St-Hilaire wrote:

>      Hello, I am just starting out with Python and ran into a problem
> day one. I am doing this statement:
> 
> input("\n\nPress the enter key to exit.")
> 
> I get the following error:
> 
>  >>> input("\n\nPress the enter key to exit.")
> 
> 
> Press the enter key to exit.
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "<string>", line 0
> 
>      ^
> SyntaxError: unexpected EOF while parsing
> 
> 
> I am using Linux (Shell) and PyCharm and get the same result when I run
> the command. I know this is stupid but any help would be appreciated.

You may be using Python 2 to run a code example written in Python 3. In 
Python 2 the string entered in input() was evaluated as a Python expression, 
and an empty string is a syntax error as you can verify with eval():

>>> eval("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 0
    
    ^
SyntaxError: unexpected EOF while parsing

To get the string as entered by the user you had to use raw_input() instead 
of input():

>>> raw_input("\n\nPress the enter key to exit.")


Press the enter key to exit.
''
>>> 




More information about the Tutor mailing list