tqdm和enumerate和file结合使用
生活大爆炸

tqdm和enumerate和file结合使用

hualala
2022-01-25 / 0 评论 / 445 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年09月04日,已超过593天没有更新,若内容或图片失效,请留言反馈。

import

from tqdm import tqdm

tqdm + for + range

for i, line in tqdm(range(10)):
    # xxxxxxx
    pass

tqdm + enumerate

for i, line in enumerate(tqdm(f)):
    # xxxxxxx
    pass

tqdm + enumerate + file

num_lines = sum(1 for line in open(file_path, 'r'))
with open(file_path) as f:
    for i, line in enumerate(tqdm(f, total=num_lines)):
        # xxxxxxx
        pass

0

评论 (0)

取消