我如何自动重新加载输出?

问题描述 投票:0回答:1

我的想法是从带有日期,月份和年份的日期开始进行计数,我想在一个小屏幕上用树莓派或类似的东西显示该计数。如何生成循环等以更新屏幕上的数字(例如每小时)?

这是我编写的代码:

import time

now = time.localtime()
day=now.tm_mday
month=now.tm_mon
year=now.tm_year
hour=now.tm_hour
minute=now.tm_min
summer=now.tm_isdst
print("Tag:", day)
print("Monat:", month)
print("Jahr:", year)



if month<4:
    j=year-2020
elif month==4:
    if day<4:
        j=year-2020
    else:
        j=year-2019
else:
    j=year-2019


if month<4:
    m=month+7
elif month==4:
    if day<7:
        m=month+7
    elif day>=7:
        m=0
    else:
        m=month-4
else:
    m=month-4




if day<7:
    t=day+24
elif day==7:
    t=0
else:
    t=day-7
print(j , ":" , m , ":" , t) 

计时器应从2020年4月7日开始工作。

python auto-update
1个回答
0
投票

此循环效果很好...

from datetime import datetime                              # for managing dates and times
import time                                                # for sleeping
while True:                                                # Just loop forever
    time.sleep(0.0)                                        # Set this to modify the tick rate
    d = datetime.now()                                     # Update time
    print(d.strftime("%A %d. %B %Y %H:%M:%S.%f"),end="\r") # Print time

如果您对strftime感到困惑,请在此处签出格式化占位符:https://strftime.org/

© www.soinside.com 2019 - 2024. All rights reserved.