raw_input() 直到输入后才会显示提示 [英] raw_input() won't show prompt until after input

查看:61
本文介绍了raw_input() 直到输入后才会显示提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它实际上比标题所暗示的更进一步,如果我在 main 的任何地方都有 raw_input() ,那么在用户输入输入之前不会发生任何事情,包括在调用 raw_input 之前应该发生的任何函数调用或输出.这是我的代码及其运行时发生的情况的一个非常简单的示例.

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)

(用户输入)

blah blah blah

(输出):

Continue?You said: blah blah blah

如果这是某种荒谬的简单修复,我深表歉意,但我已经搜索了很多但没有找到任何东西.如果与 Python 2.7 有任何关系,我正在运行 Windows 7 64 位.此外,相同的代码在解释器中完美运行,这有点奇怪.如果你们能解决这个问题,那就太好了!

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!

谢谢,将

刚刚尝试使用 sys.stdin.readline() 解决,但遇到了同样的问题.

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

推荐答案

看起来这是一个缓冲问题.我通过输入-u"命令解决了这个问题.

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

这篇关于raw_input() 直到输入后才会显示提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆