参考:Python3 Print 同一行打印显示进度条效果

参考:\r\n, \r and \n what is the difference between them? [duplicate]

参考:python的print格式化输出,以及使用format来控制。

实现思路就是不停地删除之前打印的内容,通过 '\r' 实现光标返回最前,之后会覆盖内容,没被覆盖的还会继续显示。

  • \r (Carriage Return) → moves the cursor to the beginning of the line without advancing to the next line
  • \n (Line Feed) → moves the cursor down to the next line without returning to the beginning of the line — In a *nix environment \n moves to the beginning of the line.
  • \r\n (End Of Line) → a combination of \r and \n
  1. import sys,time
  2.  
  3. # 变量
  4. total = 153
  5.  
  6. for i in range(total):
  7.  
  8. if i+1 == total:
  9. percent = 100.0
  10. print('Progress: %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\n')
  11. else:
  12. percent = round(1.0 * i / total * 100,2)
  13. print('Progress: %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\r')
  14. time.sleep(0.01)
  1. import sys,time
  2.  
  3. # 变量
  4. total = 153
  5.  
  6. for i in range(total):
  7.  
  8. if i+1 == total:
  9. percent = 100.0
  10. print('Progress: '+str(percent)+'% ['+str(i+1)+'/'+str(total)+']', end='\n')
  11. else:
  12. percent = round(1.0 * i / total * 100,2)
  13. print('Progress: '+str(percent)+'% ['+str(i+1)+'/'+str(total)+']', end='\r')
  14. time.sleep(0.01)

【451】python 同一行打印进度条的更多相关文章

  1. 初识python: flush 实现进度条打印

    通过flush(强制刷新)实现,类似进度条打印: #!/user/bin env python # author:Simple-Sir # time:20180918 #打印进度条 import sy ...

  2. python 之 time模块、datetime模块(打印进度条)

    6.9 time 模块 方法 含义 备注 time.time() 时间戳 1561013092.997079 time.strftime('%Y-%m-%d %H:%M:%S %p') 结构化时间st ...

  3. 一个简单、易用的Python命令行(terminal)进度条库

    eprogress 是一个简单.易用的基于Python3的命令行(terminal)进度条库,可以自由选择使用单行显示.多行显示进度条或转圈加载方式,也可以混合使用. 示例 单行进度条 多行进度条 圆 ...

  4. 打印进度条——(progress bar才是专业的)

    # 打印进度条——(progress bar是专业的) import time for i in range(0,101,2): time.sleep(0.1) char_num = i//2 #打印 ...

  5. python3如何打印进度条

    Python3 中打印进度条(#)信息: 代码: import sys,time for i in range(50): sys.stdout.write("#") sys.std ...

  6. 用Python基本库实现进度条

    用Python基本库实现进度条效果几个要点:1. \r,重置光标2. time.perf_counter,计算运行时间3. 用format控制输出格式 1 #progress bar2 2 #The ...

  7. Python:如何显示进度条

    首先,推荐一个组件:progressive 效果如下: 进度条和一般的print区别在哪里呢? 答案就是print会输出一个\n,也就是换行符,这样光标移动到了下一行行首,接着输出,之前已经通过std ...

  8. 利用sys打印进度条

    在很多常见中,需要对当前处理的进度进行显示,这个时候就需要进度条了,在python中,也有封装好的进度条模块,当然,也可以自己编写一个简单的进度条来帮助理解进度条的实现. 首先,需要理解一个概念,就是 ...

  9. 小技巧:with用法 pycharm控制台输出带颜色的文字 打印进度条的

    with用法 with用法在python中是一个很独特的用法,因为别的语言的中没有这个用法.所以针对这个特点我们来做一次总结,什么样的情况下可以同with  我们学到的有文件的操作,和acquire  ...

随机推荐

  1. Go入门:创建第一个Go工程

    前言 我是一名iOS开发. 因为公司后台都用的Go. 因为对服务端不了解. 所以想自己学习学习. 环境 因为自己的电脑是mac.然后在阿里云买的是centOS的服务器. 所以下面搭建的环境都是在cen ...

  2. 洛谷P1084 疫情控制(贪心+倍增)

    这个题以前写过一遍,现在再来写,感觉以前感觉特别不好写的细节现在好些多了,还是有进步吧. 这个题的核心思想就是贪心+二分.因为要求最小时间,直接来求问题将会变得十分麻烦,但是如果转换为二分答案来判断可 ...

  3. python 比较2个文件内容

    1. 通过使用md5字符串比较2个文件 import hashlib def get_file_md5(filename): '''可以比较两个文件的md5值,来比较文件内容.未使用''' md5 = ...

  4. 将Eclipse设置为黑色主题

    将Eclipse设置为黑色主题 觉得黑色的主题&配色很高大上,于是花了点时间实践出下面一种方法. 修改代码编辑区配色 修改整个软件主题 先上成果图: 但是进度条依旧是白色的,不知道怎么弄了╮( ...

  5. [译] 2017 年比较 Angular、React、Vue 三剑客

    原文地址:Angular vs. React vs. Vue: A 2017 comparison 原文作者:Jens Neuhaus 译文出自:掘金翻译计划 本文永久链接:github.com/xi ...

  6. centos7.2(一)vultr服务器购买和开通端口

    https://vultr.me/52.html 之前我们已经介绍了如何购买 Vultr 以及如何使用支付宝对 Vultr 进行充值,相关教程: VULTR 购买教程 2018 年最新图文版 VULT ...

  7. MongoDB shell 2 副本集方法

    rs.initiate()   rs.addArb()   rs.help()   rs.printReplicationInfo() 查看到副本集操作日志 rs.remove() 减少副本集节点 r ...

  8. http-server开启测试服务器

    一.安装 npm install --global http-server 二.查看使用帮助 hs -h 三.基本使用 ①默认开启占用8080端口启动一个服务器,直接打开浏览器 hs -o ②指定都端 ...

  9. Odds calculation required for the python strategy library

    Bet Class class strats.Bet(inp)[source] Here is an example of the expected string input on instantia ...

  10. 如何保证最少消费一次redis的list队列数据

    简使用pop,不能保证最少消费一次,比如pop超时可能中途丢失,或者消费者处理过程中异常而未能处理完. 解决此问题有多种方法: 1) 方法一:使用rpoplpush替代pop 这种方法相当于建立了一个 ...