疑问:
def a(line):
line+=1
ftp.dir(a)
当时不明白将a()的函数名作为dir参数后,a的参数line的值如何传?传什么?后来查了下API文档
FTP.dir(argument[, ...])
Produce a directory listing as returned by the LIST command, printing it to standard output. The optional argument is a directory to list (default is the current server directory). Multiple arguments can be used to pass non-standard options to the LIST command. If the last argument is a function, it is used as a callback function as for retrlines(); the default prints to sys.stdout. This method returns None.
重点在标红的地方,FTP.dir()用于显示目录下文件信息,可选的参数是目录列表,默认是当前目录,如果最后一个参数是函数,将像retrlines()中一样作为回调函数处理。
......
The callback function is called for each line with a string argument containing the line with the trailing CRLF stripped. The default callback prints the line to sys.stdout
回调函数被调用与每一行去除了回车的字符串。
综上:ftp.dir(a)中,ftp.dir()方法将每一行输出作为函数a()中line的值传入。