我需要创建一个将税收数据存储为默认值的类,但可以使用纳税申报表中的实际数据填充该类。例如,假设我有三个类别:收入,法定调整和税收计算,每个类别都包含多个属性。理想情况下,我想有三个自我论证,我可以传递给税收计算器的一部分。但我希望能够单独传递self字符串中的每个属性。现在我有这个:
class taxReturn:
def __init__(self):
self.income = [attribute1, attribute2, attribute3]
self.statut = [attribute4, attribute5, attribute6]
self.tax_comp = [attribute7, attribute8, attribute9]
每个属性都必须设置为可以传递的默认值,但之后会用实际数据填充。
任何帮助将不胜感激。谢谢!
答案 0 :(得分:0)
为什么不在__init__
方法中定义它?
class taxReturn:
def __init__(self, income = [attribute1, attribute2, attribute3],statut = [attribute4, attribute5, attribute6],tax_comp = [attribute7, attribute8, attribute9]):
self.income = income
self.statut = statut
self.tax_comp = tax_comp
# To create instance of taxReturn:
txR = taxReturn() # income, statut and tax_comp will take the default values defined bellow
//OR
txR = taxReturn(income = NewListOfAttribute1, statut=NewListOfAttribute2,tax_comp=NewListOfAttribute3) # income, statut and tax_comp will take the new attribute defined