joesh
joesh

Reputation: 181

Error whilst running Python .py files from terminal on Mac

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

Answers (2)

Juned Ahsan
Juned Ahsan

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

TerryA
TerryA

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

Related Questions