1 from tqdm import tqdm
2 
3 for i in tqdm(range(10000)):
4     """一些操作"""
5     pass

效果:

python模块之——tqdm(进度条)

下面说一下tqdm中的参数:

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,
postfix 以字典形式传入 详细信息 例如 速度= 10,
1 dict = {"a":123,"b":456}
2 for i in tqdm(range(10),total=10,desc = "WSX",ncols = 100,postfix = dict,mininterval = 0.3):
3     pass

结果:

python模块之——tqdm(进度条)

 1 from tqdm import trange
 2 from random import random, randint
 3 from time import sleep
 4 with trange(100) as t:
 5     for i in t:
 6         # Description will be displayed on the left
 7         t.set_description('下载速度 %i' % i)
 8         # Postfix will be displayed on the right,
 9         # formatted automatically based on argument's datatype
10         t.set_postfix(loss=random(), gen=randint(1,999), str='详细信息',
11                      lst=[1, 2])
12         sleep(0.1)

类似显示一个标题和详细信息。

效果:python模块之——tqdm(进度条)

。。。。

相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2021-12-15
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2021-06-14
  • 2022-02-28
  • 2022-12-23
相关资源
相似解决方案