tqdm,记录器位于单独的行上

发布于 2025-01-15 03:13:43 字数 783 浏览 3 评论 0原文

我查看了将日志记录“print”函数更改为“tqdm.write”,以便日志记录不会干扰进度条和< a href="https://stackoverflow.com/q/14897756/10732321">Python 进度条通过日志记录模块 他们没有我的东西 想。

我希望在不同单独行上显示日志消息和 tqdm 进度条。

我尝试了 https://stackoverflow.com/a/38739634/10732321 的答案,它给了我以下输出:

 50%|█████     | 50/100 [00:05<00:05,  9.65it/s]Half-way there!
100%|██████████| 100/100 [00:10<00:00,  9.71it/s]

当然进度条和日志消息是互斥的,但我想要下一行的 Half-way There! ,即

 50%|█████     | 50/100 [00:05<00:05,  9.65it/s]
Half-way there!
100%|██████████| 100/100 [00:10<00:00,  9.71it/s]

如何做到这一点?谢谢!

I looked at Change logging "print" function to "tqdm.write" so logging doesn't interfere with progress bars and Python Progress Bar THROUGH Logging Module and they don't have what I want.

I want to have logging messages and tqdm progress bars on different, separate lines.

I tried the answer from https://stackoverflow.com/a/38739634/10732321 which gives me the following output:

 50%|█████     | 50/100 [00:05<00:05,  9.65it/s]Half-way there!
100%|██████████| 100/100 [00:10<00:00,  9.71it/s]

Sure the progress bar and logging message is mutually exclusive, but I want the Half-way there! on the next line, i.e.

 50%|█████     | 50/100 [00:05<00:05,  9.65it/s]
Half-way there!
100%|██████████| 100/100 [00:10<00:00,  9.71it/s]

How do to this? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2025-01-22 03:13:43

实际上我更喜欢避免 tqdm 并直接这样做。
您可以为此添加自己的风味和变化。

import time


n = 25
for i in range(n):
    time.sleep(0.1)
    progress = int(i / n * 50)
    print(f'running {i+1} of {n} {progress*"."}', end='\r', flush=True)
    if i == int(n/2):
        print('\n >>> half way there')
    if i+1 == n:
        print('\nfinished process !!')

输出如下所示:

running 13 of 25 ........................
 >>> half way there
running 25 of 25 ................................................
finished process !!

I actually prefer to avoid tqdm and just do this.
You can add your own flavour and variations to this.

import time


n = 25
for i in range(n):
    time.sleep(0.1)
    progress = int(i / n * 50)
    print(f'running {i+1} of {n} {progress*"."}', end='\r', flush=True)
    if i == int(n/2):
        print('\n >>> half way there')
    if i+1 == n:
        print('\nfinished process !!')

The output looks like this:

running 13 of 25 ........................
 >>> half way there
running 25 of 25 ................................................
finished process !!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文