簡體   English   中英

帶有 Python 問題的 Visual Studio 代碼:第一行的 EOF 錯誤; 不在調試控制台中顯示輸出

[英]Visual Studio Code with Python Problem: EOF Error on 1st line; not displaying output in debug console

我正在使用 Python 語言。 每次按 f5 運行程序時,它都會在調試控制台中顯示“EOFError: EOF when reading a line”並將錯誤指向第一行。 當我嘗試在 Python IDLE(3.8 64 位)中運行相同的程序時,它運行完美。 當我刪除第一行代碼時(因為錯誤在那里),錯誤是一樣的,但現在在新的第一行。 當出現真正的錯誤(例如語法)時,調試控制台會為我指出該錯誤。 但是當我修復它時,同樣的 EOF 錯誤繼續存在。

year = int(input ("Enter a year: ")) 
if ((year % 100) == 0 and (year % 400) == 0) or ((year % 100) != 0 and (year % 4) == 0):
  print('In', year, 'February has 29 days.') 
else: 
  print('In', year, 'February has 28 days.')

這是代碼和錯誤消息的屏幕截圖: https : //i.stack.imgur.com/9GKiD.png

你描述的問題我復現了,原因是調試代碼的輸出方式。

當我們使用"console": "internalConsole",結果會輸出到" DEBUG CONSOLE ",VSCcode的這個終端目前只用於顯示輸出。 當需要輸入代碼但沒有收到輸入時,會拋出“ EOF ”“(End of file)、“文件末尾出現意外錯誤”。

解決辦法是改變調試代碼的輸出方式。

對於需要輸入的代碼,我們可以使用"console": "integratedTerminal",或者"console": "externalTerminal",當我們不設置時,VSCode默認使用"console" : "integratedTerminal"

參考: VSCode 中的控制台

我通過將launch.json設置更改為:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
        }
    ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM