Python控制檯輸出時刷新當前行內容而不是輸出新行

需求目標

執行Python程序的時候在控制檯輸出內容的時候固定一刷新內容,以下:spa

Downloading File FooFile.txt [47%]

而不是code

Downloading File FooFile.txt [47%]
Downloading File FooFile.txt [48%]
Downloading File FooFile.txt [49%]

 

實現上很簡單orm

只要增長一個 end='\r' 的print參數blog

import time
for i in range(100):
    time.sleep(0.1)
    print("\r Downloading File FooFile.txt [{}%] ".format(100-i),end='\r')
相關文章
相關標籤/搜索