Advertisements
Advertisements
Question
We will try to read input from the user. Press Ctrl-d and see what happens:
>>> s = raw_input('Enter something --> ')
Code Writing
Advertisements
Solution
In Python 2, pressing Ctrl-D sends an end-of-file signal. Since no input is supplied, raw_input() raises an EOFError exception. It can be handled as follows:
try:
s = input("Enter something --> ")
except EOFError:
print("End of input reached.")
In Windows, Ctrl-Z followed by Enter generally performs the equivalent EOF operation.
shaalaa.com
Is there an error in this question or solution?
