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.

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.