[Tutor] differences between map and partial?

Danny Yoo dyoo at hashcollision.org
Tue Sep 27 15:26:35 EDT 2016


On Tue, Sep 27, 2016 at 2:23 AM, source liu <sourceonly at gmail.com> wrote:
> Hi, List
>
> the test code as attached


Unfortunately, it didn't attach.  If you can inline the content of the
test code, that would be helpful.


>     this one works >>>>print p.map(partial(file_op,lineop=unity),input)
>     this one doesn't work >>>>print p.map(lambda x:file_op(x,unity), input)


I don't know what the function signature of file_op is.  This is an
important detail!



I would expect:

    p.map(partial(file_op,lineop=unity),input)

and:

    p.map(lambda x:file_op(x,lineop=unity), input)

to be functionality equivalent.



However, I do not know, without seeing file_op, whether:

    p.map(lambda x:file_op(x, lineop=unity), input)

versus:

    p.map(lambda x:file_op(x, unity), input)

Depending on method signature, this might not be equivalent,
especially if file_op takes in multiple keyword arguments.



Also, I don't know what you mean by "works" vs. "doesn't work": those
are human expressions that are ambiguous enough that I only know
something is wrong, but I don't know what.  :)  Can you be more
specific?  If you see error messages or stack traces, please post
them, as they are additional "signal" that may be helpful in figuring
out what's happening.


More information about the Tutor mailing list