tqdm python 指示进度的简单用法 ftplib 指示下载进度

普通工作指示程序运行进度:

import time
from tqdm import tqdm
import random

# 使用tqdm提示训练进度
with tqdm(total=1000, desc='i am desc') as pbar:
    for step in range(1000):
        
        time.sleep(0.1)
        _loss = random.random()
        
        pbar.set_postfix({
    
    'loss': '%.4f' % float(_loss)})
        pbar.update(1)


ftplib 指示文件下载进度:

with open(filename, 'wb') as fd:
    total = ftpclient.size(filename)

    with tqdm(total=total) as pbar:
        def callback_(data):
            l = len(data)
            pbar.update(l)
            fd.write(data)

        ftpclient.retrbinary('RETR {}'.format(filename), callback_)

猜你喜欢

转载自blog.csdn.net/x1131230123/article/details/114339186