参考: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. PAT 乙级 1009.说反话 C++/Java

    1009 说反话 (20 分) 题目来源 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式: 测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串.字符串由若干单词 ...

  2. php调停者模式(mediator pattern)

    差不多了,睡一觉,下次再弄. <?php /* The more classes we have in our software, the more complex their communic ...

  3. Discuz! X3 数据字典

    pre_common_admincp_cmenu 后台菜单收藏表 字段名 数据类型 默认值 允许非空 自动递增 备注 id smallint(6) unsigned    NO 是   title v ...

  4. initState 必须调用 super.initState(); 否则报错

    @override void initState() { // initState 必须调用 super.initState(); 否则报错:info: This method overrides a ...

  5. 牛客NOIP暑期七天营-普及组2D

    链接:https://ac.nowcoder.com/acm/contest/926/D来源:牛客网 在一维坐标系中,给定 n条有颜色的线段,第 i条线段的左右端点分别为 li​和 ri​,此外它的颜 ...

  6. Hibernate的级联保存、级联删除

    级联操作: 属性:cascade 值:save-update(级联保存) delete(级联删除) all(级联保存+级联删除) 优点:虽然,不用级联操作也能解决问题.但是级联操作可以减少代码量,使得 ...

  7. OOO的CSS

    应ooo要求 寻找他手写一千年的css的继承人 html { background:#f7f7f7 url(images/bg-pattern.jpg) } body { margin:; paddi ...

  8. 【CF1042F】Leaf Sets

    [CF1042F]Leaf Sets 题面 洛谷 题解 对于一个根节点\(x\),考虑其子树内的所有\(lca\)为它的叶子节点到它的距离\(d_1<d2<...<d_m\). 那么 ...

  9. Numpy中数据的常用的保存与读取方法

    小书匠 深度学习  文章目录: 1.保存为二进制文件(.npy/.npz) numpy.save numpy.savez numpy.savez_compressed 2.保存到文本文件 numpy. ...

  10. 关于C++中extern的简单笔记

    extern可以实现多文件共享同一个变量.const常量.函数. 下面结合几个例子来讲一下extern的相关性质(下述皆为多文件编译): 例1: //file1.cpp #include<ios ...