I missed the discussion on this
(http://www.python.org/peps/pep-0309.html), but then 2.5 isn't out yet.
I think partial() misses an important use case of method getting, for
instance:
lst = ['A', 'b', 'C']
lst.sort(key=partialmethod('lower'))
Which sorts by lower-case. Of course you can use str.lower, except
you'll have unnecessarily enforced a type (and excluded Unicode). So
you are left with lambda x: x.lower().
Here's an implementation:
def partialmethod(method, *args, **kw):
def call(obj, *more_args, **more_kw):
call_kw = kw.copy()
call_kw.update(more_kw)
return getattr(obj, method)(*(arg+more_args), **call_kw)
return call
This is obviously related to partial(). Maybe this implementation
should be a classmethod or function attribute, partial.method().
--
Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com