2009年1月7日星期三

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

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

2009年1月5日星期一

二个时代(以色列与巴勒斯坦)


二个时代(以色列与巴勒斯坦)