我试图让终端中的三行不同的文本显示不同的计数进度。问题是它们互相覆盖,老实说,我不知道该怎么办了。有什么建议或修复方法吗?
def first():
for i in range(50,0,-1):
sys.stdout.write("rThe current chicken is: {:<3d}".format(i))
time.sleep(1)
def second():
for i in range(100,0,-1):
sys.stdout.write("rThe current number is: {:<3d}".format(i))
time.sleep(1)
def third():
for i in range(1000,0,-1):
sys.stdout.write("rThe current cow is: {:<3d}".format(i))
time.sleep(1)
awidj = [first, second, third]
for thread in awidj:
threading.Thread(target=thread).start()
r
将只覆盖最后一行。由于这里有多个线程,因此无法控制是哪个线程。
要对控制台输出进行更精确的控制,请查看curses
模块。