简体   繁体   中英

Python code showing EOF error in Visual Studio Code but works fine in Visual Studio

在此处输入图片说明

the code is

name = input("enter your name : ")
print("your name is :" + name)

gives an EOF error in visual-studio code but works fine in Visual-Studio how do I fix the problem in Visual-Studio code ?

Just change the indentation for the vscode, it usually if there are trailing spaces.
You can do that by simply clicking F1 and then type trim trailing whitespace int the search box and select it.
OR
CTRL + K CTRL + X
If you still get the same issue try changing indentation to tabs/spaces, follow that same thing as F1 and type indentation and then select indentation to tabs/spaces as per your convenience.

When I used "console": "internalConsole", (in / .vscode / launch.json ) I encountered the same problem.

The reason is that in this mode, the result will be executed in DEBUG CONSOLE , and currently this terminal is only used for display output, so the code cannot receive the required input, and an EOF error will be displayed. (End Of File: There is an unexpected error at the end of the file.)

Solution :

Use other output methods: "console": "integratedTerminal", or "console": "externalTerminal",

Reference: console in VSCode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM