下面的问题是针对使用 PyCharm 的人。\n有嵌套for循环,tqdm用于与每个for循环对应的进度条。代码如下所示。
from tqdm import tqdm\nimport time\n\nfor i in tqdm(range(5), desc="i", colour='green'):\n for j in tqdm(range(10), desc="j", colour='red'):\n time.sleep(0.5)\nRun Code Online (Sandbox Code Playgroud)\n但问题是,每次进度条中有更新时,内部循环的进度条都会以换行符显示,如下所示。
\ni: 0%| | 0/5 [00:00<?, ?it/s]\nj: 0%| | 0/10 [00:00<?, ?it/s]\nj: 10%|\xe2\x96\x88 | 1/10 [00:00<00:04, 1.94it/s]\nj: 20%|\xe2\x96\x88\xe2\x96\x88 | 2/10 [00:01<00:04, 1.94it/s]\nj: 30%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 3/10 [00:01<00:03, 1.96it/s]\nj: 40%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 4/10 [00:02<00:03, 1.96it/s]\nj: 50%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 5/10 [00:02<00:02, 1.97it/s]\nj: 60%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 6/10 [00:03<00:02, 1.97it/s]\nj: 70%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 7/10 [00:03<00:01, 1.97it/s]\nj: 80%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 | 8/10 [00:04<00:01, …Run Code Online (Sandbox Code Playgroud)