[Python-ideas] partial with skipped arguments

Calvin Spealman ironfroggy at gmail.com
Mon Apr 23 17:44:48 CEST 2007


On 4/22/07, Collin Winter <collinw 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
>
> In Python 2.5.0:
>
> >>> import functools
> >>> def f(a, b):
> ...     return a + b
> ...
> >>> p = functools.partial(f, b=9)
> >>> p
> <functools.partial object at 0xb7d66194>
> >>> p(3)
> 12
> >>>
>
> Is this what you're looking for?
>
> Collin Winter
>

More or less but that posses two problems that I mentioned previously:
1) Relying on the names of position arguments does not feel right.
2) Buitin and extension functions don't work with that because you
can't pass positionals to them by name.

Besides, its a good excersize for me to finally get into any
moderately real hacking of CPython. I'm working on the patch right
now, one way or the other.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/



More information about the Python-ideas mailing list