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

 1 #progress bar2
2 #The sytle of prgress bar will be shown as below
3 ##16%[********->------------------------------------------]0.86s
4 #It will be divided into three part:ratio,progress bar,duration time
5 # \r, first use \r to force cursor goto beginng of a line every time
6 #
7 import time
8 scale = 50 #define the scope of char shown as progress bar
9 print('Getting Start'.center(scale//2,'-'))
10
11 start = time.perf_counter()
12
13 for i in range(scale + 1):
14 ratio = i/scale
15 star = '*' * i
16 hyphen = '-' * (scale - i)
17 dur = time.perf_counter() - start
18 print('\r{:>4.0%}[{}->{}]{:.2f}s'.format(ratio,star,hyphen,dur),end='')
19 time.sleep(0.1)

最新文章

  1. HDU 5976 Detachment 打表找规律
  2. mysql数据小姿势
  3. postgresql downgrade issue
  4. homework-02 二维的,好喝的(二维数组的各种子数组)
  5. html》meta标签笔记
  6. CentOS+Nginx+PHP+MySQL详细配置(图解)
  7. C++模板:文件操作
  8. JS将文件以form表单一样提交到后台
  9. python web环境相关
  10. C++ sqlite3解决中文排序问题
  11. java保留两位小数(不四舍五入)
  12. 【数据结构】——搜索二叉树的插入,查找和删除(递归&非递归)
  13. 移动开发day2_css预处理器_flex布局
  14. Java学习笔记二:数据类型II
  15. wxpython安装,demo下载
  16. 推文《阿里凑单算法首次公开!基于Graph Embedding的打包购商品挖掘系统解析》笔记
  17. Linux笔记-Linux命令初解2
  18. 一个web应用的诞生(5)--数据表单
  19. php菜刀分析学习
  20. 在ubuntu下使用Eclipse搭建Hadoop开发环境

热门文章

  1. Elastic_Search 和java的入门结合
  2. 异步编程之EAP
  3. request库的简单使用
  4. CSS定位(慕课网学习笔记)
  5. Focal Loss(RetinaNet)笔记 一种减小类别不平衡影响的方法
  6. 取消Ubuntu开机硬盘自检
  7. C#多线程开发-线程基础 01
  8. React事件处理、收集表单数据、高阶函数
  9. 微信小游戏 Three.js UI 2D text 简单方案
  10. SpringBoot2.x+mybatis plus3.x集成Activit7版本