[Python-ideas] reduce(func, seq, initial=0)
Florian Bruhin
me at the-compiler.org
Fri Oct 10 13:05:59 CEST 2014
* Steven D'Aprano <steve at pearwood.info> [2014-10-10 21:10:10 +1100]:
> On Fri, Oct 10, 2014 at 11:11:36AM +0200, Stephan Sahm wrote:
> > Hi folk,
> >
> > I stumbled upon the builtin reduce function. It has an optional parameter
> > initial, however if trying to set it like
> >
> > import operator as op
> > reduce(op.add, range(10), initial=0)
> >
> > I get
> >
> > TypeError: reduce() takes no keyword arguments
> >
> >
> > I think it would be really straightforward to also add keyword
> > possibilities, at least to the parameter initial.
>
> Unfortunately, this is a limitation of many built-in functions and
> methods, possibly the majority. E.g.:
>
>
> Help on built-in function getattr in module builtins:
> getattr(...)
> getattr(object, name[, default]) -> value
>
>
> but:
>
> py> getattr(None, name='spam', default=42)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: getattr() takes no keyword arguments
>
>
> I seem to recall that there was a reason for this, but I don't quite
> remember what... searching the archives may give a clue.
>
> Personally, I have no objections *in principle* to adding support for
> keyword arguments to built-ins, but it will depend on the details of why
> they weren't already supported.
FWIW, I'd also really like to see keyword arguments for these
builtins. I always have to keep myself from doing things like
"foo bar baz".split(count=1)
But as said, I suspect there is *some* reason this is not possible.
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141010/5f2f2bf6/attachment.sig>
More information about the Python-ideas
mailing list