1

代码:-

input_var=input("please enter the value")
print(input_var)

错误:- 输入一个值

运行时异常回溯(最近一次调用最后一次):文件“file.py”,第 3 行,在 n=input("Enter a value") EOFError:读取一行时出现 EOF

我已经开始学习 Python 并尝试运行这个简单的输入和打印语句。但它给了我上述错误。我尝试在在线 python 编译器上运行它并且运行良好,但是在学习门户中提供的编译器上运行时,我收到了上述错误。

4

1 回答 1

1

我尝试在在线 python 编译器上运行它并且运行良好,但是在学习门户中提供的编译器上运行时,我收到了上述错误。

input只需从“标准输入”流中读取一行。如果学习门户删除了对它的访问(关闭它或将其设置为不可读取的流),那么input当它尝试从流中读取时会立即出错。

它只是意味着您不能在该平台上对任何东西使用标准输入,所以 no input(), no sys.stdin.read(), ... (所以解决方案是“不要那样做”,这是非常特别禁止的)

在这种特定情况下,学习平台提供了一个不可读的流作为标准输入,例如 /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 was closed,你会得到一个稍微不同的错误:

> python3 test.py <&-
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    input("test")
RuntimeError: input(): lost sys.stdin
于 2019-04-09T12:35:41.530 回答