Python Interactive Interpreter always returns “Invalid syntax” on Windows

前端 未结 5 1578
迷失自我
迷失自我 2020-12-16 04:23

I\'ve encountered an extremely confusing problem. Whatever I type into the Python interpreter returns \"Invalid Syntax\". See examples below. I\'ve tried fooling around w

5条回答
  •  暖寄归人
    2020-12-16 05:08

    Now that the sample has been cleaned up it appears the problem is with the line termination.

    This isn't a solution, but what happens if you create a file t.py containing this code, run it, and then type in some text?:

    import sys; print(repr(sys.stdin.readline()))
    

    If you type something like 2+2 then with luck this will show you what the Python interpreter is getting in your example and that in turn might give some clue to the problem.

    You can also try this at the command prompt:

    python -c "import sys; print(repr(sys.stdin.readline()))"
    

    This will allow you to type one line and display the details of that one line.

提交回复
热议问题