3

From the functools documentation, the partial function is "roughly equivalent to"

def partial(func, *args, **keywords):
    def newfunc(*fargs, **fkeywords):
        newkeywords = keywords.copy()
        newkeywords.update(fkeywords)
        return func(*(args + fargs), **newkeywords)
    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords
    return newfunc

However, I don't understand the need for the lines

    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords

in the definition. If I create a partial function without these three lines it behaves exactly the same as the definition including those lines. The documentation page says that the partial object must have the three attributes func, args, and keywords, so I can see why the above function definition inludes these, but I still don't see what tangible goal they accomplish.

4

0 回答 0