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