需求目标
执行Python程序的时候在控制台输出内容的时候固定一刷新内容,如下:
Downloading File FooFile.txt [%]
而不是
Downloading File FooFile.txt [%]
Downloading File FooFile.txt [%]
Downloading File FooFile.txt [%]
实现上很简单
只要增加一个 end='\r' 的print参数
import time
for i in range():
time.sleep(0.1)
print("\r Downloading File FooFile.txt [{}%] ".format(-i),end='\r')