分为3类:患者,患者和医院。
class Patient:
def __init__(self, ID, name, age, sex, alergies):
self.ID = ID
self.name = name
self.age = age
self.sex = sex
self.alergies = alergies
def Is_old(self):
if self.age >= 60:
return True
else:
return False
def Add_patient(self, P):
pass
class Patients():
def __init__(self):
self.dict = {} # where key is a patient ID, value is an Patient object
class Hospital(Patients):
def __init__(self, name):
self.name = name
def Get_oldPatients(self):
old_patients = []
for key, value in self.dict.items(): # where an error appears
if Patient.Is_old():
old_patients.append(value)
return old_patients
出现错误
AttributeError: 'Hospital' object has no attribute 'dict'
医院类别是从患者那里继承的,因此应该具有与患者相同的属性,知道哪里出了问题吗?