您的位置:首页 > 编程语言 > Python开发

Python控制台输出时刷新当前行内容而不是输出新行

2020-01-15 01:50 337 查看

需求目标

执行Python程序的时候在控制台输出内容的时候固定一刷新内容,如下:

Downloading File FooFile.txt [47%]

而不是

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

 

实现上很简单

只要增加一个 end='\r' 的print参数

import time
for i in range(100):
time.sleep(0.1)
print("\r Downloading File FooFile.txt [{}%] ".format(100-i),end='\r')

 

  • 点赞
  • 收藏
  • 分享
  • 文章举报
clemente620 发布了260 篇原创文章 · 获赞 3 · 访问量 8724 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: