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.
This error is sometimes experienced while using online IDEs. This occurs when we have asked the user for input but have not provided any input in the input box. We can overcome this issue by using try and except keywords in Python. This is called as Exception Handling.
You should get an error like EOFError: EOF when reading a line. The acronym EOF stands for End Of File. This message literally means that the program called input() but failed to have any available input to read.
Python doesn't have built-in eof detection function but that functionality is available in two ways: f. read(1) will return b'' if there are no more bytes to read. This works for text as well as binary files. The second way is to use f.
EOF stands for End Of File . This is the point in the program where the user cannot read the data anymore. It means that the program reads the whole file till the end.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With