近期在做一些需要大量循環(huán)的工作要销,但是干循環(huán)還是不太好构回,畢竟程序一跑動(dòng)輒幾小時(shí)夏块,頁(yè)面一直不變疏咐,老實(shí)講有點(diǎn)慌。所以新學(xué)了一個(gè)進(jìn)度條tqdm給平平無(wú)奇的運(yùn)行頁(yè)面增添一分色彩
官方簡(jiǎn)述
tqdm means "progress" in Arabic (taqadum, ?????) and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado).
浪漫起來(lái)了脐供。浑塞。
參數(shù)解釋
- iterable: 可迭代,可以是一個(gè)函數(shù)政己、列表酌壕。。歇由。一般用range來(lái)計(jì)數(shù)卵牍。
Iterable to decorate with a progressbar. Leave blank to manually manage the updates.
- desc: 描述,字符串
Prefix for the progressbar.
- total: 總數(shù)沦泌,整型或浮點(diǎn)型
The number of expected iterations. If unspecified, len(iterable) is used if possible. If float("inf") or as a last resort, only basic progress statistics are displayed (no ETA, no progressbar). If gui is True and this parameter needs subsequent updating, specify an initial arbitrary large positive number, e.g. 9e9.
- leave: 完成后是否消失糊昙,布爾類型,比較奇怪的是false會(huì)消失
If [default: True], keeps all traces of the progressbar upon termination of iteration. If None, will leave only if position is 0.
- file: IO谢谦,可以導(dǎo)出進(jìn)度信息
Specifies where to output the progress messages (default: sys.stderr). Uses file.write(str) and file.flush() methods. For encoding, see write_bytes.
- ncols: 整個(gè)進(jìn)度條的寬度 ps.所有的释牺!所有的
The width of the entire output message.
- mininterval: 最小刷新間隔
Minimum progress display update interval [default: 0.1] seconds.
- maxinterval: 最大刷新間隔
Maximum progress display update interval [default: 10] seconds.
- miniters: 最小迭代間隔,試下來(lái)和mininterval沒(méi)啥區(qū)別回挽,可能在復(fù)雜迭代的時(shí)候有區(qū)別
Minimum progress display update interval, in iterations.
- ascii: 布爾類型没咙,用ASCII碼填充進(jìn)度條
If unspecified or False, use unicode (smooth blocks) to fill the meter. The fallback is to use ASCII characters " 123456789#".
- disable: 布爾類型,把進(jìn)度條搞沒(méi)千劈。這不是脫褲子X(jué)X嗎
Whether to disable the entire progressbar wrapper [default: False]. If set to None, disable on non-TTY.
- unit: 計(jì)數(shù)單位
String that will be used to define the unit of each iteration [default: it].
- unit_scale: 單位換算
If 1 or True, the number of iterations will be reduced/scaled automatically and a metric prefix following the International System of Units standard will be added (kilo, mega, etc.) [default: False]. If any other non-zero number, will scale total and n.
- dynamic_ncols: 使進(jìn)度條寬高可調(diào)
If set, constantly alters ncols and nrows to the environment (allowing for window resizes) [default: False].
- smoothing: 平滑移動(dòng)
Exponential moving average smoothing factor for speed estimates (ignored in GUI mode). Ranges from 0 (average speed) to 1 (current/instantaneous speed) [default: 0.3].
- bar_format: 自定義樣式
Specify a custom bar string formatting. May impact performance. [default: '{l_bar}{bar}{r_bar}'], where l_bar='{desc}: {percentage:3.0f}%|' and r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, ' '{rate_fmt}{postfix}]' Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage, elapsed, elapsed_s, ncols, nrows, desc, unit, rate, rate_fmt, rate_noinv, rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix, unit_divisor, remaining, remaining_s, eta. Note that a trailing ": " is automatically removed after {desc} if the latter is empty.
- initial: 設(shè)置初始值祭刚,不從0開(kāi)始的時(shí)候用
The initial counter value. Useful when restarting a progress bar [default: 0]. If using float, consider specifying {n:.3f} or similar in bar_format, or specifying unit_scale.
- position: 進(jìn)度條之前空幾行
Specify the line offset to print this bar (starting from 0) Automatic if unspecified. Useful to manage multiple bars at once (eg, from threads).
- postfix: 在進(jìn)度條之后顯示其他信息
Specify additional stats to display at the end of the bar. Calls set_postfix(**postfix) if possible (dict).
- unit_divisor: 和unit_scale配合使用,單位除數(shù)
[default: 1000], ignored unless unit_scale is True.
- write_bytes: bool, optional
If (default: None) and file is unspecified, bytes will be written in Python 2. If True will also write bytes. In all other cases will default to unicode.
- lock_args: 刷新中間量
Passed to refresh for intermediate output (initialisation, iterating, and updating).
- nrows: 高度
The screen height. If specified, hides nested bars outside this bound. If unspecified, attempts to use environment height. The fallback is 20.
- colour: 進(jìn)度條顏色
Bar colour (e.g. 'green', '00ff00').
運(yùn)行方式
迭代
for i in tqdm(range(1,5),desc='processing',colour='CYAN'):
time.sleep(1)
“手動(dòng)”
with tqdm(total=100, colour='GREEN') as pbar:
for i in range(0,100):
if i%3 == 0:
pbar.update()
else:
time.sleep(0.1)
continue