简体   繁体   中英

Python tqdm TypeError: <lambda>() takes 1 positional argument but 2 were given

I tried to create a progress bar to view progress of file transferring by using the below code.

from tqdm import tqdm
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
srv = pysftp.Connection(host=host,username=username,password=password,cnopts=cnopts)
with tqdm(unit = 'blocks', unit_scale = True, leave = False, miniters = 1, desc = 'Uploading......', total = filesize) as tqdm_instance:
    srv.put("D:\\wp-deploy.jpg","/var/www/html/wp-deploy.jpg",callback=lambda sent:tqdm_instance.update(len(sent)))

and I got this error:

TypeError: <lambda>() takes 1 positional argument but 2 were given

From the docs :

  • callback ( callable ) – optional callback function (form: func(int, int) ) that accepts the bytes transferred so far and the total bytes to be transferred

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM