You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jupyter Notebook中TQDM进度栏添加加粗描述的问题

在Jupyter Notebook中实现带加粗描述的tqdm进度栏

tqdm在Jupyter环境中,终端常用的ANSI加粗转义符(\x1b[1m)无法正确渲染,用tqdm.write又会出现多余换行,推荐直接利用Jupyter支持HTML渲染的特性解决:

from tqdm import tqdm
import time

for i in tqdm(range(10), desc="<b>global progress</b>"):
    time.sleep(0.2)

如果使用的是Jupyter专属的tqdm.notebook版本,同样适用这个方法:

from tqdm.notebook import tqdm
import time

for i in tqdm(range(10), desc="<b>global progress</b>"):
    time.sleep(0.2)

原理很简单:Jupyter会自动解析desc参数中的HTML标签,<b>标签直接实现加粗效果,既不需要额外依赖库,也不会出现换行问题,完全适配你的需求。

内容的提问来源于stack exchange,提问作者user2078621

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:00:52