[Python-ideas] partial with skipped arguments

Calvin Spealman ironfroggy at gmail.com
Sun Apr 22 14:11:55 CEST 2007

On 4/22/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> On 4/21/07, Calvin Spealman <ironfroggy at gmail.com> wrote:
> > I often wish you could bind to arguments in a partial out of order,
> > skipping some positionals. The solution I came up with is a singleton
> > object located as an attribute of the partial function itself and used
> > like this:
> >
> > def foo(a, b):
> >     return a / b
> > pf = partial(foo, partial.skip, 2)
> > assert pf(1.0) == 0.5
> The other way I've seen this proposed is as::
>     rpartial(foo, 2)
> In this particular situation, you could also just write::
>     partial(foo, b=2)
> I think the presence of keyword argument support is why rpartial
> wasn't added originally.
> Steve
> --
> I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
> tiny blip on the distant coast of sanity.
>         --- Bucky Katt, Get Fuzzy

Relying on the names of position arguments is not always a good idea,
of course. Also, it doesn't work at all with builtin (and extension?)
functions. The design is a little different, but I like it. Also, the
rpartial idea just creates multiple names for essentially the same
thing and still doesn't allow for skipping middle arguments or specify
only middle arguments, etc. I'd like to write a patch, if it would be

Read my blog! I depend on your acceptance of my opinion! I am interesting!

More information about the Python-ideas mailing list