raw_input() won't show prompt until after input

半腔热情 提交于 2019-12-02 18:48:13

问题


It actually goes further than the title suggests, if I have raw_input() anywhere in main, nothing will happen until the input has been entered by the user including any function calls or outputs that should occur before raw_input is called. Here's a very simple example of my code and what occurs when it's run.

def main():
    answer = raw_input('Continue?')
    print 'You said: ', answer

When I run it: (nothing comes on screen)

(user input)

blah blah blah

(Output):

Continue?You said: blah blah blah

I apologize if this is some sort of absurdly simple fix, but I've searched quite a bit and not been able to find anything. I'm running Windows 7 64 bit with Python 2.7 if that has anything to do with it. Also, identical code works perfectly in the interpreter which is kind of weird. If you guys can figure this out, that would be great!

Thanks, Will

Edit: Just tried to work around by using sys.stdin.readline() but had the same issue.


回答1:


It looks like it was a buffering issue. I solved it by entering the '-u' command.



来源:https://stackoverflow.com/questions/11621082/raw-input-wont-show-prompt-until-after-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!