Tqdm 是一个快速,可扩展的Python进度条,可以在 python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator)。
我的系统是window环境,首先安装python,接下来就是pip。
pip安装:
在python根目录下创建一个get-pip.py的文件,内容:
- https://bootstrap.pypa.io/get-pip.py
输出:
- python -m pip install -U pip
http://pypi.python.org/pypi/pip
下载安装包9.0
然后解压进入,CMD窗口输入:python setup.py install
然后就可以安装Tqdm了,
- pip install tqdm
- pip install -e git+https://github.com/tqdm/tqdm.git@master#egg=tqdm
基本用法:
- from tqdm import tqdm
- for i in tqdm(range(10000)):
- sleep(0.01)
- for i in trange(100):
- sleep(0.1)
- pbar = tqdm(["a", "b", "c", "d"])
- for char in pbar:
- pbar.set_description("Processing %s" % char)
- with tqdm(total=100) as pbar:
- for i in range(10):
- pbar.update(10)
- pbar = tqdm(total=100)
- for i in range(10):
- pbar.update(10)
- pbar.close()
统计所有python脚本的行数:
- $ time find . -name '*.py' -exec cat \{} \; | wc -l
- 857365
- real 0m3.458s
- user 0m0.274s
- sys 0m3.325s
- $ time find . -name '*.py' -exec cat \{} \; | tqdm | wc -l
- 857366it [00:03, 246471.31it/s]
- 857365
- real 0m3.585s
- user 0m0.862s
- sys 0m3.358s