Jupyter Notebook中的tqdm反复打印新的进度条 [英] tqdm in Jupyter Notebook prints new progress bars repeatedly
问题描述
我正在使用tqdm
在Jupyter笔记本中运行的脚本中打印进度.我正在通过tqdm.write()
将所有消息打印到控制台.但是,这仍然给了我这样的偏斜输出:
I am using tqdm
to print progress in a script I'm running in a Jupyter notebook. I am printing all messages to the console via tqdm.write()
. However, this still gives me a skewed output like so:
也就是说,每次必须打印新行时,下一行上都会打印一个新的进度条.通过终端运行脚本时不会发生这种情况.我该如何解决?
That is, each time a new line has to be printed, a new progress bar is printed on the next line. This does not happen when I run the script via terminal. How can I solve this?
推荐答案
尝试使用tqdm.notebook.tqdm
代替tqdm
,如这就像将导入更改为:
from tqdm.notebook import tqdm
祝你好运!
编辑:经过测试,看来tqdm
在Jupyter笔记本中的文本模式"下实际上可以正常工作.很难说,因为您没有提供最小示例,但是看来您的问题是由每个示例中的打印语句引起的迭代.在每次状态栏更新之间,打印语句都会输出一个数字(〜0.89),这会使输出混乱.尝试删除打印语句.
After testing, it seems that tqdm
actually works fine in 'text mode' in Jupyter notebook. It's hard to tell because you haven't provided a minimal example, but it looks like your problem is caused by a print statement in each iteration. The print statement is ouputting a number (~0.89) in between each status bar update, which is messing up the output. Try removing the print statement.
这篇关于Jupyter Notebook中的tqdm反复打印新的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!