AttributeError: 'list' object has no attribute 'isdigit'
这是我一直接受的持续性错误,我正在搜索数据并获取人名,表格和分数,我试图将分数变为平均值,
pls enter a fullname >> Geoffrey Chiasson
Geoffrey Chiasson F 6 1 3
我正试图从中获得6 1和3。
这是我的代码:
def searchQuerySurname(alist):
searchQuery = [ ]
nofound = 0 ## no found set at 0
surname = input("pls enter a fullname >> ") ## asks user for surname
surname = surname.lower() ## converts to lower case
for row in alist:
if row[0].lower() == surname: ## surname appears in row0
searchQuery.append(row) ## appends results
numbers =int(filter(searchQuery.isdigit, str1))
nofound = nofound + 1 ## increments variable
if nofound == 0:
print("there were no matches")
return searchQuery
我崩溃时得到了这个:
AttributeError: 'list' object has no attribute 'isdigit'
答案 0 :(得分:0)
您尝试将字符串方法isdigit
应用于列表:
>>> 'abc'.isdigit()
False
>>> '123'.isdigit()
True
>>> [].isdigit()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'isdigit'
您应该将检查isdigit
应用于不列出searchQuery
,而是应用于列表的每个元素(string)
。
答案 1 :(得分:0)
var getMax = function(){
var content = $("#content");
return content.height();
}
首先使用map(int, filter(str.isdigit, searchQuery))
过滤searchQuery
,然后将str.isdigit
应用于每个剩余的结果。