摘要:
python list转换字符串报错TypeError: sequence item 0: expected str instance, int found场景:将列表转化为指定分...
python list转换字符串报错TypeError: sequence item 0: expected str instance, int found
场景:将列表转化为指定分隔符的字符串,列表当中有数字时会报如上错误。
user.txt: alex:202cb962ac59075b964b07152d234b70:1234:0 tom:202cb962ac59075b964b07152d234b70:2234:0 test01:202cb962ac59075b964b07152d234b70::0
1 2 | d_user内容如下:
|
上面是做某个项目中的实际数据,转化成列表碰到这个错误提示,可以直接忽略这部分,往下看..
检验:
>>> L1 = ['alex', '202cb962ac59075b964b07152d234b70', '1234', 0]
'0'
>>> ':'.join(L1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 3: expected str instance, int found
解决办法:
>>> ':'.join('%s' %i for i in L1)
'alex:202cb962ac59075b964b07152d234b70:1234:0'
还没有评论,来说两句吧...