python "".join() 出错TypeError: sequence item 0: expected string, int found

python中使用join连接list时出现类型错误的解决办法

例:
>>> ls = [1,2,3]
>>> print ','.join(ls)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found

解决办法对list中的元素进行类型转换到string

>>> print ','.join('%s' % id for id in ls)
1,2,3

 

ref : http://hi.baidu.com/zhumq92/item/3e58dd395c4b040dcfb9fe62

posted @ 2014-01-27 20:28  WenLe  阅读(15010)  评论(0编辑  收藏  举报