1

EDIT: Also refer to this - PyCharm: How to debug `raw_input()` input from keyboard?

I'm writing a code with for loop and taking 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:"))

But I'm getting the following error - End of File.

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

However this code is working fine when I run it from terminal. I read somewhere that this can happen if you don't close your file after reading/writing. It might have happened with me as well (but in a different project). What should I do in that case? I've tried restarting the IDE (Pycharm) as well.

Also, what is really happening in the background that this error is coming?

Jugal Anchalia
  • 393
  • 1
  • 2
  • 11
  • If you check out the documentation on EOFError https://docs.python.org/2/library/exceptions.html#exceptions.EOFError, you see that it occurs when it encounters an EOF condition without reading in any data. If it works in your terminal but not in Pycharm, there might be some formatting issue when you type user input in the Pycharm IDE – Peter Wang Aug 02 '17 at 19:32
  • I'm not able to type any user input in Pycharm at all. It was working perfectly fine till yesterday. It says **(N.B.: the file.read() and file.readline() methods return an empty string when they hit EOF.)** Today, I was experimenting with read() & readline() methods in a separate file. Could that be the reason? What can I do in that case? – Jugal Anchalia Aug 02 '17 at 19:52
  • If you were experimenting with it in a separate file, probably not. Python automatically closes any open file as soon as the program finishes – Peter Wang Aug 02 '17 at 19:54
  • Then I guess this is Pycharm related issue and not anything else. Thanks Peter. I've tried some solutions, but not successful yet, will update once it is fixed – Jugal Anchalia Aug 02 '17 at 20:09

1 Answers1

2

Found the answer. This was an issue specific to Jetbrains Pycharm. Apparently while using PyCharm where the run configuration includes "Show Command Line Afterwards", it works. The raw_input is blocked when this setting is off.

Edit Configuration > config > check show command line afterwards.

Refer to this.

https://youtrack.jetbrains.com/issue/PY-20551

Jugal Anchalia
  • 393
  • 1
  • 2
  • 11