前提
python tqdmライブラリにてプログレスバーを使った簡単なコンソールアプリケーションを作成しています。
Windows環境にてバッチファイルからpython実行しています。
2つの処理にプログレスバーを設けて、続けて処理を実行すると、2つ目のプログレスバーの表示が崩れてしまいます。
下記テストプログラム中のbar1が完了していない状態になっているのではないかと憶測しますが、対策はございますでしょうか。
ソースコード
python
1■tqdmtest.py 2 3import time 4from tqdm import tqdm 5 6def test(): 7 bar1 = tqdm(range(10), desc="bar1") 8 for i in range(10): 9 time.sleep(0.1) 10 bar1.update(1) 11 12 bar2 = tqdm(range(10), desc="bar2") 13 for i in range(10): 14 time.sleep(0.1) 15 bar2.update(1) 16 17test()
コンソール表示
output
1 C:\Users\user1\Desktop\test\tqdmtest>python tqdmtest.py 2 bar1: 100%|████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 9.27it/s] 3 bar2: 0%| | 0/10 [00:00<?, ?it/s] 4 bar2: 10%|███████▋ | 1/10 [00:00<00:00, 9.41it/s] 5 bar2: 20%|███████████████▍ | 2/10 [00:00<00:00, 9.31it/s] 6 bar2: 30%|███████████████████████ | 3/10 [00:00<00:00, 9.26it/s] 7 bar2: 40%|██████████████████████████████▊ | 4/10 [00:00<00:00, 9.22it/s] 8 bar2: 50%|██████████████████████████████████████▌ | 5/10 [00:00<00:00, 9.24it/s] 9 bar2: 60%|██████████████████████████████████████████████▏ | 6/10 [00:00<00:00, 9.23it/s] 10 bar2: 70%|█████████████████████████████████████████████████████▉ | 7/10 [00:00<00:00, 9.19it/s] 11 bar2: 80%|█████████████████████████████████████████████████████████████▌ | 8/10 [00:00<00:00, 9.21it/s] 12 bar2: 90%|█████████████████████████████████████████████████████████████████████▎ | 9/10 [00:00<00:00, 9.23it/s] 13 bar1: 100%|████████████████████████████████████████████████████████████████████████████| 10/10 [00:02<00:00, 4.61it/s] 14 bar2: 100%|████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 9.24it/s]
実現したいこと
bar2のプログレスバーが改行せずに表示される
output
1C:\Users\user1\Desktop\test\tqdmtest>python tqdmtest.py 2bar1: 100%|████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 9.27it/s] 3bar2: 100%|████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 9.24it/s]

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。