티스토리 뷰

728x90
반응형

모듈 설치

pip install tqdm

 

사용법

from tqdm import tqdm
for i in tqdm(range(100)):
    # some code
    pass

위와 같이 사용할 수 있으며, tqdm(range(N)) 은 trange 로 줄여서 사용할 수도 있다.

 

사용 예시

from tqdm import trange
from time import sleep

for i in trange(100):
    sleep(0.1)

# 출력 결과
# 100%|█████████████████████████████████████████████████████████████████████| 100/100 [00:10<00:00,  9.46it/s]

 

아래 이미지는 위 코드를 실행했을 때 나타나는 결과임.

CLI 사용 예시

Python 스크립트 뿐만 아니라 CLI 으로도 사용 가능하다.

아래 예시는 시간이 아닌 bytes 값으로도 progress 추적이 가능토록 한다.

$ seq 9999999 | tqdm --bytes | wc -l
75.2MB [00:00, 217MB/s]
9999999

$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
    > backup.tgz
 32%|██████████▍                      | 8.89G/27.9G [00:42<01:31, 223MB/s]

 

 

출처

https://github.com/tqdm/tqdm

 

GitHub - tqdm/tqdm: :zap: A Fast, Extensible Progress Bar for Python and CLI

:zap: A Fast, Extensible Progress Bar for Python and CLI - GitHub - tqdm/tqdm: :zap: A Fast, Extensible Progress Bar for Python and CLI

github.com

 

기타 의견

개인적으로 PoC 실행했을 때 진행률을 나타내주면 정말 친절한 PoC 가 될 것 같은 생각이 듬.

728x90
반응형
댓글