How To Resolve Eoferror: Eof When Reading A Line?
Code:- input_var=input('please enter the value') print(input_var) Error:- Enter a value Runtime Exception Traceback (most recent call last): File 'file.py', line 3, in
Solution 1:
I have tried running it on a online python compiler and it runs fine but when running on a compiler provided in a learning portal I am getting the above error.
input
simply reads one line from the "standard input" stream. If the learning portal removes access to it (either closes it or sets it as a non-readable stream) then input
is going to immediately get an error when it tries to read from the stream.
It simply means you can't use stdin for anything on that platform, so no input()
, no sys.stdin.read()
, … (so the resolution is "don't do that", it's pretty specifically forbidden)
In this specific case, the learning platform provides a non-readable stream as stdin e.g. /dev/null:
# test.pyinput("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
if stdin were closed, you'd get a slightly different error:
> python3 test.py <&-
Traceback (most recent call last):
File "test.py", line 4, in <module>
input("test")
RuntimeError: input(): lost sys.stdin
Post a Comment for "How To Resolve Eoferror: Eof When Reading A Line?"