python:进度条的使用(tqdm)

摘要:为python程序进度条,可以知道程序运行进度。

python中,常用的进度条模块是tqdm,将介绍tqdm的安装和使用
1、安装tqdm:

pip install tqdm

2、tqdm的使用:

(1)在for循环中的使用:

from tqdm import tqdm

for i in tqdm(range(10000)):
	print(i)

在for循环中使用tqdm是最常见了,因为知道循环的次数

(2)在while中使用tqdm

from tqdm import tqdm

count = 10000
pbar = tqdm(total = count)
i = 0
while i < count:
	print(i)
	i += 1
	pbar.update(1)

在while中使用进度条,也需要知道循环的次数,本人常在opencv处理视频中使用tqdm, 可大概知道处理的进度。