基本应用
参数
iterable=None,
desc=None, 传入str类型,作为进度条标题(类似于说明)
total=None, 预期的迭代次数
leave=True,
file=None,
ncols=None, 可以自定义进度条的总长度
mininterval=0.1, 最小的更新间隔
maxinterval=10.0, 最大更新间隔miniters=None, ascii=None, unit=‘it‘,unit_scale=False, dynamic_ncols=False, smoothing=0.3,bar_format=None, initial=0, position=None, postfix 以字典形式传入 详细信息 例如 速度= 10,
eg:
from tqdm import trange
from random import random, randint
from time import sleep
with trange(100) as t:
for i in t:
# Description will be displayed on the left
t.set_description(‘下载速度 %i‘ % i)
# Postfix will be displayed on the right,
# formatted automatically based on argument‘s datatype
t.set_postfix(loss=random(), gen=randint(1,999), str=‘详细信息‘,
lst=[1, 2])
sleep(0.1)
循环体
from tqdm import tqdm
for iIndex in tqdm(range(1000)):
pass
枚举遍历
from tqdm import tqdm
for iIndex,filename in enumerate(tqdm(jsons)):
pass
多进程
from tqdm import tqdm
from concurrent.futures import ProcessPoolExecutor
import sys
from colorama import Fore
from joblib import Parallel, delayed
def progress_bar(desc, array):
return tqdm(array,
total=len(array),
file=sys.stdout,
ascii=‘ >‘,
desc=desc,
bar_format="%s{l_bar}%s{bar:30}%s{r_bar}" % (Fore.RESET, Fore.BLUE, Fore.RESET))
test = range(int(1e4))
def parallelize(desc, func, array, max_workers):
return Parallel(n_jobs=max_workers)(delayed(func)(a) for a in progress_bar(desc, array))
def identity(x):
return x
parallelize("", identity, test, 2)