Leo Breebaart wrote:
I'm not complaining as such -- sep.join(str(i) for i in seq) is
not *that* ugly, but what annoys me is that I don't understand
*why* this was never changed.

py> chars = [u'ä', u'å']
py> ', '.join(chars)
u'\xe4, \xe5'
py> ', '.join(str(c) for c in chars)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 1, in <generator expression>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128)
py> u', '.join(chars)
u'\xe4, \xe5'
py> u', '.join(unicode(c) for c in chars)
u'\xe4, \xe5'


Currently, str.join will return a unicode object if any of the items to be joined are unicode. That means that str.join accepts unicode objects as well as str objects. So you couldn't just call str on all the objects...

Maybe you could call str or unicode on each object as appropriate though... If str.join already determines that it must return a unicode object, it could call unicode on all the items instead of str... I don't know the code well enough though to know if this is feasible...

STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to