1
2

More than 1 year has passed since last update.

python処理の進捗可視化

Posted at

通常処理や機械学習、Deeplearningなどの実行時に現在の進捗を確認したいと思ったことはありませんでしょうか。今回はそれが叶えられるライブラリ「tqdm」を用い、プログレスバーで表示してみましょう。

テスト環境の作成

python -m venv tqdmtest
.\tqdmtest\Scripts\activate

ライブラリをインストール

pip install tqdm

テスト実行

import time
from tqdm import tqdm

for i in tqdm(range(5)):
    time.sleep(1)

プログレスバーの前に文字を入れる

from tqdm import tqdm
for i in tqdm(range(5), desc="test"):
    pass

プログレスバーの後ろに文字を入れる

from tqdm import tqdm
for i in tqdm(range(5), postfix="test"):
    pass

プログレスバーを非表示

disable=Trueを引数で指定することで、プログレスバーを非表示にすることができます。

from tqdm import tqdm
for i in tqdm(range(5), disable=True):
    pass

プログレスバーの表示記号を変更する

ascii=[記号]を引数で指定することで、プログレスバー内に表示される文字列を変更することができます。

from tqdm import tqdm
for i in tqdm(range(5), ascii="//"):
    pass

1
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
1
2