4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonのtqdmで進捗バーが表示されない時の対処法

Posted at

pythonのtqdmを使えば進捗バーが表示されます.

from tqdm import tqdm
import time

for i in tqdm(range(10)):
    time.sleep(0.1)
実行結果
100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00,  9.75it/s]

ただ,例えば次のような場合は進捗バーはなぜか表示されません.

from tqdm import tqdm
import time

for i in tqdm(reversed(range(10))):
    time.sleep(0.1)
実行結果
10it [00:01,  9.75it/s]

この場合,次のようにすれば解決できました.

from tqdm import tqdm
import time

for i in tqdm(reversed(range(10)), total=10):#totalでfor文の繰り返し回数を指定してあげる
    time.sleep(0.1)
実行結果
100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00,  9.77it/s]
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?