【发布时间】:2020-05-31 04:02:51
【问题描述】:
我有一个线程每 1 秒计算一次时间以获得总经过时间。这很好用,但即使在打印另一行之后,我也需要让它保持在同一行。目前它正在这样做:
[~] 00:00:02
ok #this is a test print to see if it stays on the same line and of course it dosen't.
[~] 00:00:08
def total_elapsed_time(start):
while True:
elapsed_time = time.time() - start
print(colorama.Fore.LIGHTBLUE_EX + "[~] " + time.strftime("%H:%M:%S", time.gmtime(elapsed_time)), end="\r")
time.sleep(1) #updates every second
这是我的代码。我一直在阅读有关 \r \n 和 \r\n 和 \r 的部分工作,但我仍然需要它始终保持在同一条线上。我不确定这是否可能,尽管我已经看到它是用其他语言完成的,所以我认为它是。
【问题讨论】:
-
这需要“curses”或类似的库。
标签: python python-3.x printing newline