4

I have this python program:

import board

theBoard = board.Board()
theBoard.setup_new_game()
theBoard.display()

inputStr = raw_input('Enter move \"x y\":')
print inputStr

Board is a class I wrote, which displays an Othello board. When I run this program, it immediately stops and waits for input. When I enter something and hit return, it then displays the board and shows the input prompt below it.

Do I need to use curses and stuff to get this to behave properly, or am I just missing something basic? As far as I can tell, this should print the board, print the prompt, then wait for me to give input.

Almo
  • 15,538
  • 13
  • 67
  • 95

1 Answers1

6

Usually this is due to the output not being flushed properly. Sometimes the output driver waits to actually print text until it feels it needs to for efficiency reasons, but sometimes it causes issues such as these. I don't know the exact interface for flushing with the API you are using, but should be simple to find.

Dougvj
  • 6,409
  • 2
  • 23
  • 18
  • 2
    Bingo! Thanks a lot; I ended up at http://stackoverflow.com/questions/230751/how-to-flush-output-of-python-print and I used the `sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)` solution – Almo May 29 '12 at 15:13