【问题标题】:Python stdin request coming before stdout printsPython stdin 请求在 stdout 打印之前发出
【发布时间】:2014-04-06 13:33:35
【问题描述】:

我最近一直在尝试学习 Python 3.3,但遇到了问题。这是我正在使用的测试代码:

print('should print before stdin')
x = raw_input('Enter something: ')

这是输出的样子:

>>something
should print before stdin
Enter something:

为什么打印语句在标准输入之后?

【问题讨论】:

  • 嗯,那里的“>>”说了很多东西。尝试不要从空闲状态运行它。关闭 idle 并双击 .py 文件,看看是否有效。如果这只是您正在运行的代码,它应该可以正常运行.. 至少在 python 上

标签: python printing stdin raw-input


【解决方案1】:

在 Python 3.X 中,raw_input("") 已被删除,因此请改用 input()。 参考这个docs

print('should print before stdin')
x = input('Enter something: ')

输出

should print before stdin
Enter something: yes

Process finished with exit code 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2012-12-04
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多