[英]int() argument must be a string or a number, not 'generator'
I am stuck with two errors, and I assume it comes from my misuse of the classes, but I can't figure out how to fix that...我遇到了两个错误,我认为这是由于我对类的滥用,但我不知道如何解决这个问题......
I get :我得到:
AttributeError: Organism instance has no attribute 'remove' AttributeError:有机体实例没有属性“删除”
or或者
int() argument must be a string or a number, not 'generator' int() 参数必须是字符串或数字,而不是“生成器”
def filtre_vecteurs(organisms):
nb_organisms = len(organisms)
vector_size = len(organisms[0].vector)
for i in range(vector_size):
tmp = 0
for j in range(nb_organisms):
organisms[j].vector[i] = int(organisms[j].vector[i])
tmp += organisms[j].vector[i]
if tmp == nb_organisms :
for j in range(0, nb_organisms):
organisms[j].remove(organisms[j].vector[i])
return organisms
"organisms" is a list of objets “organisms”是一个对象列表
"organisms[0].vector" :vector of the first object of the list "organisms[0].vector" : 列表第一个对象的向量
a vector looks like this [1,0,1,1...]一个向量看起来像这样 [1,0,1,1...]
thanks a lot for your help !非常感谢你的帮助 !
Your errors are:你的错误是:
This is in line organisms[j].remove(organisms[j].vector[i])
Here, it seems organisms[j]
which is an organism
has no remove()
method.这符合
organisms[j].remove(organisms[j].vector[i])
在这里,似乎organisms[j]
其是organism
还没有remove()
方法。 You probably want to remove the element organisms[j].vector[i]
from organisms[j].vector
:您可能想从
organisms[j].vector
删除元素organisms[j].vector[i]
:
organisms[j].vector.remove(organisms[j].vector[i])
This is due to line:这是由于行:
organisms[j].vector[i] = int(organisms[j].vector[i])
Are you sure that organisms[j].vector[i]
is a number/string?.您确定
organisms[j].vector[i]
是数字/字符串吗?。 Can you try printing it and see if it is indeed a number/string?您可以尝试打印它并查看它是否确实是数字/字符串吗?
Here are things to look at:以下是需要注意的事项:
Error 1:错误 1:
What is the type of organisms[j].vector[i]?生物体[j].vector[i]的类型是什么? From the error message, it appears as though it is a generator, so has no conversion to int.
从错误消息来看,它似乎是一个生成器,因此没有转换为 int。
Error 2:错误 2:
What does your organism class look like?你的有机体类是什么样的?
From the line:从行:
organisms[j].remove(organisms[j].vector[i])
which I presume causes your second error.我认为这会导致您的第二个错误。 Your Organism class has no method called 'remove'.
您的 Organism 类没有名为“remove”的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.