A trivial question about print

Alex Martelli aleax at aleax.it
Thu Apr 11 09:06:24 EDT 2002


Max M wrote:
        ...
> def newJoin(self, items):
>      return self.join([str(i) for i in items])
> 
> Is there any case where it isn't applicable at all?

Could be a disaster if any item was Unicode:

>>> print ''.join(('mapp','erch',u'\u00e8')).encode('latin-1')
mapperchè

vs:

>>> print ''.join([str(x) for x in 
('mapp','erch',u'\u00e8')]).encode('latin-1')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>>

but presumably you could have something subtler that used
str() or unicode() as appropriate (maybe not trivial to
determine what's "appropriate" in each given case).


Alex




More information about the Python-list mailing list