简体   繁体   中英

How do you write multiple lines of replaceable console output in python?

I am trying to have three different lines of text in the terminal display the different count progresses. The problem is they overwrite each other and honestly I don't know what to do anymore. Any tips or fixes?

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 will just overwrite the last line that was written. Since you have multiple threads here, there is no way to control which one that is.

For more precise control over console output, check out the curses module .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM