python腳本進度條

1. 定義進度條


  from tqdm import tqdm

def
tqdmWrapViewBar(*args, **kwargs): pbar = tqdm(*args, **kwargs) # make a progressbar last = [0] # last known iteration, start at 0 def viewBar(a, b): pbar.total = int(b) pbar.update(int(a - last[0])) # update pbar with increment last[0] = a # update last known iteration return viewBar, pbar # return callback, tqdmInstance

 

2. 實例化進度條

cbk, pbar = tqdmWrapViewBar(ascii=True, unit='b', unit_scale=True)

 

3. 使用進度條

def sftp_down_file(host, logfile):
    try:
        t = paramiko.Transport((host, 22))
        t.connect(username="root", pkey=pkfile)
        sftp = paramiko.SFTPClient.from_transport(t)
        sftp.get(logfile, "456.txt", callback=cbk) #使用回調函數展示進度條
        t.close()
    except Exception as e:
        print(e)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章