Python: EOFError: EOF when reading a line

2019-01-23 17:07发布

问题:

This may be repeated, but none of the existing answers solved my problem.

So, I'm using Python 2.7, and I get this error (title) whenever I try this:

number = int(raw_input('Number : '))

I tried this in Sublime Text 2, compileronline.com and in codecademy; it fails in the first 2 of this sites. It works on codecademy and in the terminal compiler, but I can't understand exactly why it is failing.

回答1:

The issue here is that Sublime text 2's console doesn't support input.

To fix this issue, you can install a package called SublimeREPL. SublimeREPL provides a Python interpreter that takes in input.

And as for compileronline.com, you need to provide input in the "STDIN Input" field on the lower right of the website.



回答2:

try:
    value = raw_input()
    do_stuff(value) # next line was found 
except (EOFError):
   break #end of file reached

This seems to be proper usage of raw_input when dealing with the end of the stream of input from piped input. Refer this post



回答3:

import numpy
n=int(raw_input())
a=[]
for i in range(n):
    a.append(input())
x=numpy.array(a)

min=x[0]
for j in range(0,n):

        if x[j]<min:
                min=x[j]

x = numpy.int32(x)
print min