首页 > 解决方案 > 在执行我的 Python 代码时出现“EOFError: EOF when reading a line”。我该如何解决?

问题描述

我正在使用 Python3.8 制作一个程序,该程序在sys.stdin. 这是代码:

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")

如果用户没有提供参数,程序将继续使用标准输入。问题是:当我运行程序时,最后一行出现错误。这是输出:

$ 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

我的代码有什么问题?:/

标签: pythoninputstdinsys

解决方案


推荐阅读