[英]How to resolve EOFError: EOF when reading a line?
碼:-
input_var=input("please enter the value")
print(input_var)
錯誤: - 輸入一個值
運行時異常回溯(最近一次調用最后一次):文件“file.py”,第3行,在n =輸入(“輸入值”)EOFError:讀取行時的EOF
我已經開始學習Python並試圖運行這個簡單的輸入和打印語句。 但它給了我上面的錯誤。 我已經嘗試在在線python編譯器上運行它並且運行正常,但是當在學習門戶中提供的編譯器上運行時,我收到上述錯誤。
我已經嘗試在在線python編譯器上運行它並且運行正常,但是當在學習門戶中提供的編譯器上運行時,我收到上述錯誤。
input
只是從“標准輸入”流中讀取一行。 如果學習門戶刪除了對它的訪問(要么關閉它或將其設置為不可讀的流),那么當它嘗試從流中讀取時, input
將立即出現錯誤。
它只是意味着你不能在該平台上使用stdin作為任何東西,所以沒有input()
,沒有sys.stdin.read()
,...(所以分辨率是“不要那樣做”,它是非常明確禁止的)
在這種特定情況下,學習平台提供不可讀的流作為stdin,例如/ dev / null:
# test.py
input("test")
> python3 test.py </dev/null
Traceback (most recent call last):
File "test.py", line 4, in <module>
input("test")
EOFError: EOF when reading a line
如果stdin被關閉 ,你會得到一個稍微不同的錯誤:
> python3 test.py <&-
Traceback (most recent call last):
File "test.py", line 4, in <module>
input("test")
RuntimeError: input(): lost sys.stdin
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.