I got 'EOFError: EOF when reading a line' in the execution of my Python code. How do I fix this?

Viewed 29

I'm using Python3.8 to make a program that takes an input from the user with the help of sys.stdin. This is the code:

import sys

try:    
    file = open(sys.argv[1], "r")
    source = file.read()
    file.close()    
except:
    source = sys.stdin.read()
    
input("\nPress enter to continue... \n")

If the user doesn't provide an argument, the program continues with the standard input. The problem is: When I run the program, I get an error at the last line. Here is the output:

$ apt-get install google* --print-uris | ./scrFiles/pythonFiles/code.py

Press enter to continue... 
Traceback (most recent call last):
  File "./scrFiles/pythonFiles/code.py", line 12, in <module>
    input("\nPress enter to continue... \n")
EOFError: EOF when reading a line

What is wrong with my code? :/

0 Answers
Related