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?

4
  • If you check out the documentation on EOFError 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 Commented Aug 2, 2017 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? Commented Aug 2, 2017 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 Commented Aug 2, 2017 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 Commented Aug 2, 2017 at 20:09

1 Answer 1

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

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

Comments

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.