Reputation: 181
I have a slight problem trying to run a python program from the terminal on my Mac. When my '.py' program has a 'input ("press the enter key to find out.")' command the terminal gives the following error message once you've pressed the 'return' key.
Traceback (most recent call last):
File "word_problems.py", line 6, in <module>
input ("press the enter key to find out.")
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Can someone explain where the problem is?
Thanks in advance.
Upvotes: 0
Views: 821
Reputation: 68715
Use raw_input instead of input when you want accept string as an input. input takes only Python expressions and it does an eval on them.
Upvotes: 1
Reputation: 60024
In python 2.7, input()
is identical to eval(raw_input())
.
Thus, when you hit return, you actually enter ''
, and:
>>> eval('')
Traceback (most recent call last):
File "<PythonForiOS-Input>", line 1, in <module>
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
Instead, use raw_input()
.
Upvotes: 1