'Waiting' animation in command prompt (Python)

前端 未结 4 1843
忘了有多久
忘了有多久 2020-12-30 05:11

I have a Python script which takes a long time to run. I\'d quite like to have the command line output to have a little \'waiting\' animation, much like the swirly circle we

4条回答
  •  囚心锁ツ
    2020-12-30 05:40

    Just another pretty variant

    import time
    
    bar = [
        " [=     ]",
        " [ =    ]",
        " [  =   ]",
        " [   =  ]",
        " [    = ]",
        " [     =]",
        " [    = ]",
        " [   =  ]",
        " [  =   ]",
        " [ =    ]",
    ]
    i = 0
    
    while True:
        print(bar[i % len(bar)], end="\r")
        time.sleep(.2)
        i += 1
    

提交回复
热议问题