每隔00秒运行一次python代码(python)

时间:2017-08-18 17:35:02

标签: python raspberry-pi

如果在python中时钟变为00秒,你将如何运行代码? (12:31:00,13:24:00,...... HH:MM:00)我正在使用rpi,所以当00秒打击时,代码会打印一些东西,否则等待。

我对代码的想法是..但我的格式错误。谢谢!

while True:
    if datetime == HH:MM:00
      print format(datetime.datetime.now())

    else 
      wait

1 个答案:

答案 0 :(得分:2)

可以计算到当前分钟结束的时间:

while True:
    now = datetime.datetime.now()
    time.sleep(60.0 - now.second - now.microsecond / 1e6)
    # do the work
相关问题