Ftp.dir中的回调函数

疑问:

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()中一样作为回调函数处理。

FTP. retrlines ( command [callback ] )

......

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的值传入。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值