Why doesn't join() call str() on its arguments?

Nick Coghlan ncoghlan at iinet.net.au
Thu Feb 17 05:54:12 EST 2005


Leo Breebaart wrote:
> All I've been able to find is a 1999 python-dev post by Tim
> Peters which would seem to indicate he doesn't understand it
> either:
> 
>     "string.join(seq) doesn't currently convert seq elements to
>      string type, and in my vision it would. At least three of us
>      admit to mapping str across seq anyway before calling
>      string.join, and I think it would be a nice convenience
>      [...]"
> 
> But now it's 2005, and both string.join() and str.join() still
> explicitly expect a sequence of strings rather than a sequence of
> stringifiable objects.

There's a more recent discussion than that, because I tried to change it shortly 
after I offered a patch to fix a corner case for string subclasses.

This seems to be the last relevant message in the thread:
http://mail.python.org/pipermail/python-dev/2004-August/048516.html

So it was tried, but we found too many weird corner cases we weren't quite sure 
what to do with. At that point, "explicit is better than implicit" kicked in :)

A shame, since it was both faster and more convenient than using a list comp. 
But the convenience wasn't worth the ambiguity of the semantics.

Cheers,
Nick.

P.S. For anyone else that uses Firefox:

Linking the pydev keyword to
"http://www.google.com/search?q=site:mail.python.org+inurl:python-dev+%s"

and the pylist keyword to
"http://www.google.com/search?q=site:mail.python.org+inurl:python-list+%s"

makes searching the archives on python.org really easy. Of course, knowing what 
you're looking for because you were a participant in the discussion helps, too ;)

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list