TypeError:序列索引必须是整数

时间:2015-03-19 19:14:42

标签: range python-2.5

我只是在每3个字符之间添加一个","。

print totalpoints
points = ','.join([totalpoints[i:i+3] for i in range(0, totalpoints, 3)])

输出:

875
TypeError: sequence index must be integer

1 个答案:

答案 0 :(得分:1)

我不知道你究竟想做什么。但如果我没有错,以下将解决您的问题。

>>> totalpoints = 875123123 
>>> totalpoints = str(totalpoints)
>>> points = ','.join([totalpoints[i:i+3] for i in range(0, len(totalpoints), 3)])
>>> points
'875,123,123'