0

我需要创建一个将税收数据存储为默认值的类,但可以使用纳税申报表中的实际数据填充该类。例如,假设我有三个类别:收入、法定调整和税收计算,每个类别都包含几个属性。理想情况下,我想要三个自我参数,我可以将它们传递给税收计算器的各个部分。但我希望能够单独传递 self 字符串中的每个属性。现在我有这个:

class taxReturn:

    def __init__(self): 

        self.income = [attribute1, attribute2, attribute3]
        self.statut = [attribute4, attribute5, attribute6]
        self.tax_comp = [attribute7, attribute8, attribute9]

每个属性都必须设置为可以传递的默认值,然后用实际数据填充。

任何帮助,将不胜感激。谢谢!

4

1 回答 1

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
于 2015-10-02T14:01:04.500 回答