[Python-ideas] textFromMap(seq , map=None , sep='' , ldelim='', rdelim='')

Nick Coghlan ncoghlan at gmail.com
Tue Oct 26 11:51:52 CEST 2010

On Tue, Oct 26, 2010 at 2:00 AM, Laurens Van Houtven <lvh at laurensvh.be> wrote:
> Hm. I suppose the need for this would be slightly mitigated if I understood
> why str.join does not try to convert the elements of the iterable it is
> passed to strs (and analogously for unicode).
> Does anyone know what the rationale for that is?

To elaborate on Guido's answer, omitting automatic coercion makes it
fairly easy to coerce via str, repr or ascii (as appropriate), or else
to implicitly assert that all the inputs should be strings (or
buffers) already.

Once you put automatic coercion inside str.join, the last option
becomes comparatively hard to do.

Note that easy coercion in str.join is one of the use cases that
prompted us to keep map as a builtin though:

sep.join(map(str, seq))
sep.join(map(repr, seq))
sep.join(map(ascii, seq))

The genexp equivalents are both slower and harder to read than the
simple map invocations.

To elaborate on Terry's answer as well - when join was the function
string.join, people often had troubling remembering if the sequence or
the separator argument came first. With the str method, while some
people may find it odd to have the method invocation on the separator,
they typically don't forget the order once they learn it for the first


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list