python - TQDM progress bar, change text format - Stack Overflow

I'm trying to display a progress bar in a jupyter notebook with a bold description preceding the b

I'm trying to display a progress bar in a jupyter notebook with a bold description preceding the bar.

for i in tqdm(range(10), desc='\x1b[1mglobal progress'):
    time.sleep(.2)

seems to produce

I tried different options, qqdm and rich seem to work, but the former is stuck to 4 years ago, the latter seems to have a little too much overhead.

Following the comments I did this:

for i in tqdm(range(10), desc=tqdm.write('\x1b[1m global progress', end="")):
    time.sleep(.2)

which renders the text in bold, but introduces an unwanted newline. The end="" argument does not seem to have any effect. Actually I have exactly the same result if I use the built-in print function

Thanks for any help

I'm trying to display a progress bar in a jupyter notebook with a bold description preceding the bar.

for i in tqdm(range(10), desc='\x1b[1mglobal progress'):
    time.sleep(.2)

seems to produce

I tried different options, qqdm and rich seem to work, but the former is stuck to 4 years ago, the latter seems to have a little too much overhead.

Following the comments I did this:

for i in tqdm(range(10), desc=tqdm.write('\x1b[1m global progress', end="")):
    time.sleep(.2)

which renders the text in bold, but introduces an unwanted newline. The end="" argument does not seem to have any effect. Actually I have exactly the same result if I use the built-in print function

Thanks for any help

Share Improve this question edited Mar 10 at 15:35 user2078621 asked Mar 10 at 15:07 user2078621user2078621 1413 silver badges12 bronze badges 6
  • ANSI escape code \x1b[1m is being interpreted as part of the string, rather than as a formatting code use tqdm.write – steve-ed Commented Mar 10 at 15:10
  • Write an answer to your own question if you have found the answer yourself – steve-ed Commented Mar 10 at 15:29
  • thanks @steve-ed, see edited question please. What am I missing? – user2078621 Commented Mar 10 at 15:35
  • actually, this seems to be Jupyter notebook specific. On IPython it is working – user2078621 Commented Mar 10 at 15:48
  • I see this was also posted here. (An updated version is also here.) Please, when posting the same question in various forums link to all the associated places you post the same questions. This saves people trying to help you from wasting effort saying the same thing someone may have already said. Additionally, part of the purpose of such forums is to help others find an answer and if things aren't connected you create silos of information ... – Wayne Commented Mar 17 at 19:50
 |  Show 1 more comment

2 Answers 2

Reset to default 0

For those wanting to use this with tqdm.notebook - the Jupyter Notebook progressbar decorator for iterators, you'll need both tqdm and ipywidgets installed, then try:

from tqdm.notebook import tqdm
import time
for i in tqdm(range(5), desc='

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744838955a4596438.html

相关推荐

  • python - TQDM progress bar, change text format - Stack Overflow

    I'm trying to display a progress bar in a jupyter notebook with a bold description preceding the b

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信