我需要在npm install lodash@4.17.5
循环中使用我的对象,但是会出错。
以下是代码:
for
并抛出此错误:
class Citizen():
type='Citizen'
colony='init'
def __init__(self,value1,value2):
self.name=value1
self.gender=value2
def __iter__(self):
return iter(self.name)
def print_citizen(self,colonyname):
for i in self.Citizen:
if (Citizen.colony==colonyname) :
print(i.name,' | Citizen | ',i.gender)
知道如何解决这个问题吗?
答案 0 :(得分:0)
不确定你要做什么,但这会以这种方式运作:
class Citizen():
type='Citizen'
colony='init'
def __init__(self,value1,value2):
self.name=value1
self.gender=value2
def __iter__(self):
return iter(self.name)
def print_citizen(self,colonyname):
if (self.colony==colonyname) :
print(self.name,' | Citizen | ',self.gender)
然后:
myCitizen = Citizen("Bob", "Male")
myCitizen.print_citizen(colonyname)