[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)
Nick Coghlan
ncoghlan at gmail.com
Sun Aug 10 14:33:49 CEST 2014
(switching from python-dev to python-ideas)
FWIW, I don't consider str.join *or* sum with an empty string as the
starting point to be particularly intuitive ways of joining iterables of
strings.
str.join was invented before we had keyword-only arguments as a common
construct, and before print became an ordinary function that accepted a
"sep" keyword-only argument.
I'd be interested in seeing a concrete proposal for a "concat" builtin that
accepted a "sep" keyword only argument. Even if such a PEP ends up being
rejected, it would hopefully help cut short the *next* potentially
interminable thread on the topic by gathering the arguments for and against
in a more readily accessible place.
Regards,
Nick.
On 10 Aug 2014 18:26, "Stephen J. Turnbull" <stephen at xemacs.org> wrote:
> Alexander Belopolsky writes:
> > On Sat, Aug 9, 2014 at 3:08 AM, Stephen J. Turnbull <stephen at xemacs.org
> >
> > wrote:
> >
> > > All the suggestions
> > > I've seen so far are (IMHO, YMMV) just as ugly as the present
> > > situation.
> > >
> >
> > What is ugly about allowing strings? CPython certainly has a way to to
> > make sum(x, '')
>
> sum(it, '') itself is ugly. As I say, YMMV, but in general last I
> heard arguments that are usually constants drawn from a small set of
> constants are considered un-Pythonic; a separate function to express
> that case is preferred. I like the separate function style.
>
> And that's the current situation, except that in the case of strings
> it turns out to be useful to allow for "sums" that have "glue" at the
> joints, so it's spelled as a string method rather than a builtin: eg,
> ", ".join(paramlist).
>
> Actually ... if I were a fan of the "".join() idiom, I'd seriously
> propose 0.sum(numeric_iterable) as the RightThang{tm]. Then we could
> deprecate "".join(string_iterable) in favor of "".sum(string_iterable)
> (with the same efficient semantics).
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140810/9d71f3d8/attachment.html>
More information about the Python-ideas
mailing list