[Python-Dev] Partial function application 'from the right' (original) (raw)
Collin Winter collinw at gmail.com
Fri Jan 30 00:29:47 CET 2009
- Previous message: [Python-Dev] Partial function application 'from the right'
- Next message: [Python-Dev] Include C++ code in the ctypes test suite?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: splitcomma = partial(str.split, sep = ',') [snip] I've created a patch which adds a 'partialright' function. The two examples above: >>> import functools, math >>> splitcomma = functools.partialright(str.split, ',') >>> splitcomma('a,b,c') ['a', 'b', 'c'] >>> log10 = functools.partialright(math.log, 10.0) >>> log10(100.0) 2.0
Can you point to real code that this makes more readable?
Collin
- Previous message: [Python-Dev] Partial function application 'from the right'
- Next message: [Python-Dev] Include C++ code in the ctypes test suite?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]