[Python-ideas] partial with skipped arguments

Steven Bethard steven.bethard at gmail.com
Sun Apr 22 17:15:58 CEST 2007


On 4/22/07, Calvin Spealman <ironfroggy at gmail.com> wrote:
> 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)
>
> 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
> considered.

Well, I can pretty much guarantee you'll get the two responses above,
so if you post a patch, make sure you let python-dev know that you've
already considered these options and don't see them as satisfactory.
Your best bet of convincing people is probably to find a few
real-world use cases and post the corresponding code.

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



More information about the Python-ideas mailing list