0

I keep getting the EOF error when I execute the Python script using stream redirection.

Script

name=input('Enter your name : ')
print ('Welcome ' + name)
input('Press \'ENTER\' to exit!')

Execution command:

helloworld.py < input.dat

Error:

Enter your name : Welcome Gunit
Press 'ENTER' to exit!Traceback (most recent call last):
  File "D:\Reference\Python\Codes\helloworld.py", line 28, in <module>
    input('Press \'ENTER\' to exit!')
EOFError: EOF when reading a line
1
  • Hi Gunit. Since the below answer did seem to solve your problem, can you mark the answer as accepted? That would remove this question from the "unanswered questions" list. Thanks. Commented Sep 29, 2021 at 5:10

1 Answer 1

1

Your code reads two lines from the file (one for the name, and one for the "Enter to exit"). Your input file only has one line in it.

Therefore, Python reaches the End-Of-File indication before it can read the 2nd line.

To fix, ensure that your input.dat has at least two lines, or delete the 2nd input() call.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks... it worked... I had 2 lines in input.dat, but the 2nd line had no character to be read by input()...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.