参考: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
import sys,time

# 变量
total = 153 for i in range(total): if i+1 == total:
percent = 100.0
print('Progress: %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\n')
else:
percent = round(1.0 * i / total * 100,2)
print('Progress: %s [%d/%d]'%(str(percent)+'%',i+1,total),end='\r')
time.sleep(0.01)
import sys,time

# 变量
total = 153 for i in range(total): if i+1 == total:
percent = 100.0
print('Progress: '+str(percent)+'% ['+str(i+1)+'/'+str(total)+']', end='\n')
else:
percent = round(1.0 * i / total * 100,2)
print('Progress: '+str(percent)+'% ['+str(i+1)+'/'+str(total)+']', end='\r')
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. geany写C语言,printf打印中文时显示乱码

    原因 geany设置了编码格式为utf8 运行时显示出的cmd窗口编码格式为GBK 解决方法 要么修改geany编码,要么修改cmd窗口编码. 修改geany编辑器为GBK编码格式 编辑=>首选 ...

  2. dfs 排列组合——找所有子集(重复元素和不重复元素)

    17. 子集 中文 English 给定一个含不同整数的集合,返回其所有的子集. 样例 样例 1: 输入:[0] 输出: [ [], [0] ] 样例 2: 输入:[1,2,3] 输出: [ [3], ...

  3. php单例型(singleton pattern)

    搞定,吃饭 <?php /* The purpose of singleton pattern is to restrict instantiation of class to a single ...

  4. Java精通并发-Lock锁方法原理详解

    继续上一次https://www.cnblogs.com/webor2006/p/11756563.html的Lock文档说明进行阅读: 以上就是对于Lock类中官方解读,下面再纵览一下它里面的方法: ...

  5. JMeter聚合报告的参数含义

    Label----每个请求的名称,比如HTTP请求等 #Samples----发给服务器的请求数量 Average----单个请求的平均响应时间 毫秒ms Median----50%请求的响应时间   ...

  6. Use /* eslint-disable */ to ignore all warnings in a file. 报错

    有了eslint的校验,可以来规范开发人员的代码,是挺好的.但是有些像缩进.空格.空白行之类的规范,但是稍有不符合,就会在开发过程中一直报错,太影响心情和效率了.所以,还是会选择关闭eslint校验. ...

  7. 31、Python程序中的协程操作(greenlet\gevent模块)

    一.协程介绍 协程:是单线程下的并发,又称微线程,纤程.英文名Coroutine.一句话说明什么是协程:协程是一种用户态的轻量级线程,即协程是由用户程序自己控制调度的. 对比操作系统控制线程的切换,用 ...

  8. pm2日志管理插件

    pm2的日志模块默认是每一个服务进程都分配两个默认的日志文件 普通日志 错误日志 这两个日志文件存放于/root/.pm2/logs中,如果pm2管理5个服务,那么该文件夹下总共有10个日志文件,并且 ...

  9. For 32-bit BOOL is a signed char, whereas under 64-bit it is a bool.

    https://stackoverflow.com/questions/31267325/bool-with-64-bit-on-ios/31270249#31270249 Definition of ...

  10. Nested List Weight Sum

    Description Given a nested list of integers, return the sum of all integers in the list weighted by ...