Tqdm - Multiple Progress Bars With Nested For Loops In Pycharm
The below question is for people who use PyCharm. There are nested for loops and tqdm is used for progress bars corresponding to each for loop. The code is shown below. from tqdm i
Solution 1:
The solution is two fold.
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.
Along with the
position
argument also set theleave
argument. The code should look like this. I have addedncols
so that the progress bar doesn't take up whole of the console.
from tqdm import tqdm
import timefor 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]
The updates happen on the same line.
Post a Comment for "Tqdm - Multiple Progress Bars With Nested For Loops In Pycharm"