更新时间:2023-01-13 09:54:58
解决方案有两个.
转到编辑配置".单击正在使用的运行/调试配置.应该有一个选项在输出控制台中模拟终端".检查那个.添加图片以供参考.
Go to "Edit configurations". Click on the run/debug configuration that is being used. There should be an option "Emulate terminal in output console". Check that. Image added for reference.
与 position
参数一起,还设置 leave
参数.代码应如下所示.我添加了 ncols
以便进度条不会占据整个控制台.
Along with the position
argument also set the leave
argument. The code should look like this. I have added ncols
so that the progress bar doesn't take up whole of the console.
from tqdm import tqdm
import time
for i in tqdm(range(5), position=0, desc="i", leave=False, colour='green', ncols=80):
for j in tqdm(range(10), position=1, desc="j", leave=False, colour='red', ncols=80):
time.sleep(0.5)
现在运行代码时,控制台的输出如下图所示.
When the code is now run, the output of the console is as shown below.
i: 20%|████████▍ | 1/5 [00:05<00:20, 5.10s/it]
j: 60%|████████████████████████▌ | 6/10 [00:03<00:02, 1.95it/s]
更新发生在同一行.