Join strings - very simple Q.
7stud
bbxx789_05ss at yahoo.com
Sat Mar 24 13:41:12 EDT 2007
On Mar 24, 8:30 am, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> In case you are feeling that the ','.join(l) looks a bit jarring, be aware
> that there are alternative ways to write it. You can call the method on the
> class rather than the instance:
>
> jl = str.join(',', l)
> jl = unicode.join(u'\u00d7', 'l')
>
>... the catch is you need to know
> the type of the separator in advance.
When I try the latter example, I get an error:
lst = ["hello", "world"]
print unicode.join(u"\u00d7", lst)
Traceback (most recent call last):
File "test1.py", line 2, in ?
print unicode.join(u"\u00d7", lst)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd7' in
position 5: ordinal not in range(128)
More information about the Python-list
mailing list