Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';列表';对象没有属性';isdigit';从找到的数据中提取数字_Python - Fatal编程技术网

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” 您不应该将checking
isdigit
应用于列表
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))