[Python-Dev] Partial function application 'from the right'

Collin Winter collinw at gmail.com
Fri Jan 30 00:29:47 CET 2009


On Thu, Jan 29, 2009 at 6:12 AM, Ben North <ben at redfrontdoor.org> wrote:
> Hi,
>
> I find 'functools.partial' useful, but occasionally I'm unable to use it
> because it lacks a 'from the right' version.  E.g., to create a function
> which splits a string on commas, you can't say
>
>   # Won't work when called:
>   split_comma = partial(str.split, sep = ',')
[snip]
> I've created a patch which adds a 'partial_right' function.  The two
> examples above:
>
>   >>> import functools, math
>
>   >>> split_comma = functools.partial_right(str.split, ',')
>   >>> split_comma('a,b,c')
>   ['a', 'b', 'c']
>
>   >>> log_10 = functools.partial_right(math.log, 10.0)
>   >>> log_10(100.0)
>   2.0

Can you point to real code that this makes more readable?

Collin


More information about the Python-Dev mailing list