[Python-Dev] Missing operator.call

Guido van Rossum guido at python.org
Wed Feb 4 21:47:01 CET 2009


On Wed, Feb 4, 2009 at 11:48 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> If there is interest in this and no reason why it shouldn't be done, I
>> can write up an issue in the tracker and provide a patch.
>
> I think there is a tricky design choice to make wrt. argument passing.
> IIUC, you don't care much about arguments, so you could probably live
> with
>
> def call(o):
>    return o()
>
> Somebody proposed that you pass arguments once, and get an
> "arguments bound" object, i.e.
>
> def call(*args, **kwds):
>    def func(o):
>        return o(*args, **kwds)
>    return func
>
> Finally, it seems that Guido is advocating an API where arguments get
> passed along with the callable, i.e.
>
> def call(o, *args, **kwds):
>    return o(*args, **kwds)
>
> which would make call a synonym for apply (and would also provide for
> the first definition as a special case). However, with that API, it
> isn't so easy anymore to pass the same arguments to all callables
> (unless it is no arguments that you want to pass).

My version is in line with the other operators in the operator module.
The version that binds the arguments and returns a callable is already
available as functools.partial.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list