在Python中更新时钟程序而不创建新行

8 浏览
0 Comments

在Python中更新时钟程序而不创建新行

我正在为树莓派创建一个程序,在命令行中,程序显示如下的日期和时间,我想添加重复或更新,以便程序启动后日期和时间为当前值。这段代码来自一个在线教程,我想尝试对它进行修改,但遇到了死胡同。我目前正在学习Python。

#!/usr/bin/python
import time
now = time.strftime("%c")
print "current date and time " + time.strftime("%c")

admin 更改状态以发布 2023年5月22日
0
0 Comments

我想这个问题之前已经被回答了,在这里

你可以使用一个末尾的逗号来避免打印新的一行:

print "this should be",
print "on the same line"

0
0 Comments

以下代码将每秒钟在同一位置打印时间:

import time
while True:
    time.sleep(1.0)
    print("\r" + str(time.time()), end="")

0