Python tqdm and print weird printout order
本问题已经有最佳答案,请猛点这里访问。
我有以下Python 3代码:
1 2 3 4 5 | from tqdm import tqdm print("Before") for _ in tqdm(range(10)): pass print("After") |
我希望将以下输出发送到终端:
1 2 3 | Before 100%|##########| 10/10 [00:00<?, ?it/s] After |
但是,我得到的是:
1 2 3 | 100%|##########| 10/10 [00:00<?, ?it/s] Before After |
即 相对于我的代码,打印输出的顺序错误。 我还尝试过在两次调用
1 2 | Before 100%|##########| 10/10 [00:00<?, ?it/s]After |
同样,将
为什么它以这种意外的方式表现?
编辑:这个问题是关于在tqdm循环之前或之后使用打印功能的特定情况。 在tqdm循环中还有其他与打印消息有关的类似问题,此处并非如此。
默认情况下,tqdm打印到