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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM