【发布时间】:2013-12-13 00:26:24
【问题描述】:
在尝试检索列表列表的长度时,我收到以下错误:“TypeError: 'float' object is not callable”
我的代码如下所示:
list = []
for line in text:
regex = re.search("(.*) (.*) (.*)")
a = float(regex.group(1))
b = float(regex.group(2))
c = float(regex.group(3))
list.append([a, b, c])
newlist = []
for entry in list:
if entry[0] < 10:
newlist.append(entry)
if len(newlist) >1:
do something
列表列表('newlist')的生成没有问题,例如[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
而且绝对是一个列表,即type 'list'
但是当我尝试使用时:
len(list)
我刚刚收到 TypeError。我可能错过了一些非常明显的事情,但我看不出我做错了什么,有人可以帮忙吗?
谢谢你:)
【问题讨论】:
-
不要使用
list作为变量名——它会影响内置函数。 -
请保持提问者的代码不变。如果
list已被重用,则可能其他名称(包括len)已被隐藏。