TQDM Python FTP程序中出现语法错误



当我尝试运行以下代码时,它会给我一个语法错误。谁能告诉我如何纠正这个错误吗。谢谢,

with tqdm(unit='blocks', unit_scale=True, leave=False, miniters=1, desc=f'Uploading {thumbnailname}......', total=filesize) as tqdm_instance:
session.storbinary('STOR ' + thumbnailname, file, 2048,
callback=lambda sent: tqdm_instance.update(len(sent)))

试试这个:

如果您制作一个回调函数,该函数将在每次迭代中更新tqdm,那么它就会起作用。

with tqdm(unit = 'b', unit_scale = True, leave = False, miniters = 1, desc = 'file name', total = filesize) as tqdm_instance:
def tqdm_callback(data):
# update progress bar and write out data
tqdm_instance.update(len(data))
raw_file.write(data)
# check to see if download has completed
if (raw_file.tell() == filesize):
# close down the progress bar
# prevents an extra ftp call which generates a timed out exception
tqdm_instance.close()
# make ftp data request
ftp.retrbinary(f"RETR suppl/{raw_filename}", tqdm_callback)

来自pythonmethylprep库https://github.com/FoxoTech/methylprep/blob/master/methylprep/download/geo.py#L152

然而,我来这里是为了寻找更多的例子,因为我认为如果FTP块有错误,TQDM会感到困惑,必须重新发送。在这种情况下,循环的总块数将发生变化,并且循环可能在所有块完成之前就结束了。

最新更新