我正在尝试学习如何在python中正确地嵌套类(我习惯在C ++中的其他结构中使用结构)。以下是我的尝试:
class Patient(object):
class FutureMirceraRegimen(object):
def __init__ (self, dose = None, frequency = None):
self.dose = dose
self.frequency = frequency
class CurrentMirceraRegimen(object):
def __init__(self, dose = None, frequency = None, lastdose = None):
if dose is None:
self.dose = input("What is the current dose (in mcg)?")
if frequency is None:
self.frequency = input("What is the current frequency (in weeks)?")
if lastdose is None:
self.lastdose = input("How many days have elapsed since the patient's last dose of Mircera?")
class Hgb(object):
def __init__(self, level = None, increasing = None, decreasing = None):
if level is None:
self.level = input("What is the Hgb level?")
if increasing is None:
self.increasing = input("Is the Hgb increasing? (answer Y/N)")
if decreasing is None:
self.decreasing = input("Is the Hgb decreasing? (answer Y/N)")
def __init__(self, identifier = None, age = None, gender = None, weight = None, currentminceraregimen, hgb, futureminceraregimen):
self.identifier = input("Patient identifier?")
self.identifier = int(self.identifier)
self.age = input("Patient age?")
self.age = int(self.age)
self.gender = input("Input 1 if patient is female, input 2 if patient is male.")
self.gender = int(self.gender)
self.weight = input("Input rounded weight in KG.")
self.weight = int(self.weight)
self.futureminceraregimen = Patient.FutureMirceraRegimen
self.currentminceraregimen = Patient.CurrentMirceraRegimen
self.hgb = Patient.Hgb
Jeff = Patient
但是,每当我运行代码时,我都会收到一条错误消息,说我在默认参数后面有一个非默认参数。我不明白为什么,因为我唯一的非默认参数在所有类中都是self。任何帮助将不胜感激!