SyntaxError: unexpected character after line continuation character when reading py file from Terminal

created at 05-21-2021 views: 0

Description

If you meet this problem when reading a python script from you Terminal (like CMD of Windows), you probably enter the path to the python interpreter rather than the command line of Windows.

Let's see an example.

assuming we have a python script under path:

D:\python-learing\Hello.py

you can access this script by opening the CMD and typing:

C:\Users\admin>D:\python-learing\Hello.py
Hello World

but if you are doing this in a python environment:

C:\Users\admin>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> D:\python-learing\Hello.py
  File "<stdin>", line 1
    D:\visualization\PyCharmProject\matplotlib\lianxi\Hello.py
                                                             ^
SyntaxError: unexpected character after line continuation character
>>>

you will get this error.

Solution

So the solution is quite easy, just type quit() to exit your python environment and run you command outside.

Please log in to leave a comment.