我正在编写一个使用FTPLib来获取文件的模块.我想找到一种方法将值(除了块)传递给回调.基本上,我的回调是
def handleDownload(block, fileToWrite):
fileToWrite.write(block)
Run Code Online (Sandbox Code Playgroud)
我需要打电话
ftp.retrbinary('RETR somefile', handleDownload)
Run Code Online (Sandbox Code Playgroud)
并让它传递文件句柄.有没有办法做到这一点?
您可以fileToWrite使用lambda关闭变量:
fileToWrite = open("somefile", "wb")
ftp.retrbinary("RETR somefile", lambda block: handleDownload(block, fileToWrite))
Run Code Online (Sandbox Code Playgroud)