2

I am trying to really understand what is happening in this line of python to get it to pull the incoming data to a string instead of writing it to an outfile.

ftp.retrlines("RETR " + filename, lambda s, w=outfile.write: w(s+"\n"))

It looks like retrlines is getting a command and a callback -- but then there is an additional 3rd argument. What is it doing?

Also, I understand lambdas as explained here (which look very similar to javascript anonymous function callbacks) but don't see how to apply that to this case, where lamda s is defined in the second argument Why are Python lambdas useful?

There are too many unfamilar things happening in this python code. Can someone explain what is happening in this line.

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244

1 Answers1

6

No there is not an optional third argument to the retrlines function, but an optional second argument to the lambda.

The retrlines function gets passed two arguments:

"RETR " + filename

and

lambda s, w=outfile.write: w(s+"\n")
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621