【问题标题】:python print isn't work during the for looppython print 在for循环期间不起作用
【发布时间】:2016-07-25 00:52:38
【问题描述】:

我想在 for 循环期间检查 python 2.7 中的某个值。我想打印一个当前时间。问题是在 for 循环期间 print 没有运行。当 for 循环结束后,就进行打印操作。我的源代码如下。

[代码]

import time

def display():
    print "Something..."

while(1):
    time.sleep(1)
    display()

谁知道原因?或解决方案?

【问题讨论】:

  • 每秒打印一次。屏幕填满后,它可能看起来停止了,但实际上它只是在滚动。那么,你观察到了什么?
  • “不工作”对问题的描述不够详细,无法让我们为您提供帮助。
  • 尝试直接从 shell/命令行运行它。

标签: python time while-loop


【解决方案1】:
import time

def display(something):
    print something

index = 1
while(1):
    time.sleep(1)
    display(index)
    index += 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多