Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 2.7.2, Cygwin, raw_input: why does it only print the prompt after I give the input?

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.

like image 863
Almo Avatar asked Dec 20 '25 05:12

Almo


1 Answers

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.

like image 65
Dougvj Avatar answered Dec 24 '25 12:12

Dougvj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!