鱼C论坛

 找回密码
 立即注册

tqdm模块显示进度条

已有 173 次阅读2021-11-5 11:09 |个人分类:Python

Python版本3.6.4

以下代码在VS code和IDLE中,进度条都不能单行显示。
from time import sleep
from tqdm import tqdm

bar = tqdm(range(1,20))

for each in bar:
    bar.set_description('Processing %s' %each)
    sleep(1)

加入ncols参数后在VS code中可正常单行显示,而IDLE中不能。
from time import sleep
from tqdm import tqdm

bar = tqdm(range(1,20),ncols=100)

for each in bar:
    bar.set_description('Processing %s' %each)
    sleep(1)

tqdm的help文档对ncols的解释:
ncols  : int, optional
The width of the entire output message. If specified, dynamically resizes the progressbar to stay within this bound. If unspecified, attempts to use environment width. The fallback is a meter width of 10 and no limit for the counter and statistics. If 0, will not print any meter (only stats).

ncols参数控制输出消息的宽度,如果数值过大,则会多行显示;如果为 0,则不会显示进度条。所以需要将ncols参数设置为适当的值。

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-27 16:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部