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

Fredrik Lundh fredrik at pythonware.com
Wed Feb 16 14:34:16 EST 2005


Jeff Shannon wrote:

> One possibility I can think of would be Unicode.  I don't think that implicitly calling str() on 
> Unicode strings is desirable.

it's not.  but you could make an exception for basestring types.

> Of course, one could ensure that unicode.join() used unicode() and str.join() used str(), but I 
> can conceive of the possibility of wanting to use a plain-string separator to join a list that 
> might include unicode strings.

yes.

> Whether this is a realistic use-case

it is.  mixing 8-bit ascii strings with unicode works perfectly fine, and is a good
way to keep memory use down in programs that uses ascii in most cases (or
for most strings), but still needs to support non-ascii text.

I've proposed adding a "join" built-in that knows about the available string types,
and does the right thing for non-string objects.  unfortunately, the current crop of
py-dev:ers don't seem to use strings much, so they prioritized really important stuff
like sum() and reversed() instead...

</F> 






More information about the Python-list mailing list