编辑:另请参阅 - PyCharm: How to debug `raw_input()` input from keyboard?
我正在用 for 循环编写代码并采用 raw_input
for turn in range(4):
guess_row[0] = int(raw_input("Player 1 Guess Row:"))
guess_col[0] = int(raw_input("Player 1 Guess Col:"))
guess_row[1] = int(raw_input("Player 2 Guess Row:"))
guess_col[1] = int(raw_input("Player 2 Guess Col:"))
但我收到以下错误 - 文件结束。
Traceback (most recent call last):
File "/Users/bonjugal/Desktop/Pycharm/Battleship_Game.py", line 52, in <module>
guess_row[0] = int(raw_input("Player 1 Guess Row:"))
EOFError
但是,当我从终端运行此代码时,它运行良好。我在某处读到,如果您在读/写后不关闭文件,可能会发生这种情况。它也可能发生在我身上(但在不同的项目中)。在这种情况下我该怎么办?我也尝试过重新启动 IDE(Pycharm)。
另外,在这个错误即将到来的背景下到底发生了什么?