Python 属性错误:';列表';对象没有属性';isdigit';从找到的数据中提取数字
这是我一直收到的一个持续性错误,我正在搜索数据,它得到了人们的姓名、表格和分数,我试图将分数计算到平均值Python 属性错误:';列表';对象没有属性';isdigit';从找到的数据中提取数字,python,Python,这是我一直收到的一个持续性错误,我正在搜索数据,它得到了人们的姓名、表格和分数,我试图将分数计算到平均值 AttributeError: 'list' object has no attribute 'isdigit' 我正试着从中得到61和3 这是我的密码: pls enter a fullname >> Geoffrey Chiasson Geoffrey Chiasson F 6 1 3 当它崩溃时,我得到了以下信息: def searchQuerySur
AttributeError: 'list' object has no attribute 'isdigit'
我正试着从中得到61和3
这是我的密码:
pls enter a fullname >> Geoffrey Chiasson
Geoffrey Chiasson F 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
您尝试将字符串方法
isdigit
应用于列表:
AttributeError: 'list' object has no attribute 'isdigit'
abc.isdigit()
假的
>>>“123”。isdigit()
真的
>>>[….isdigit()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:“list”对象没有属性“isdigit”
您不应该将checkingisdigit
应用于列表searchQuery
,而是应用于列表中的每个元素(string)
>>> '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'
首先使用
str.isdigit
过滤searchQuery
,然后将int
应用于所有剩余的结果。您为什么要首先尝试使用searchQuery.isdigit
?看起来您复制了一些代码,但不了解它的作用。即使您在那里使用了正确的方法引用,您也不能在filter()
对象上使用int()
。这是我试图编辑的一些旧代码。您可以编辑它吗?包含数据的变量的名称是什么。@Rasnaamt:代码应该做什么?您的编号
变量已分配,但从未使用过。还有str1
,已使用但从未分配。也许你应该把这条线全部删除。我需要澄清一下。什么是输入和输出数据?应该对数据执行哪些操作?
map(int, filter(str.isdigit, searchQuery))