简体   繁体   English

需要使用属性的默认值创建类

[英]Need to Create Class with Default Values for Attributes

I need to create a class that that stores tax data as default values, but that can be populated with actual data from tax returns. 我需要创建一个将税收数据存储为默认值的类,但可以使用来自纳税申报单的实际数据填充该类。 So for instance, let's say I have three categories: income, statutory adjustments, and tax computation, each which contains several attributes. 例如,假设我有三类:收入,法定调整和税额计算,每一个包含几个属性。 Ideally, I would like to have three self arguments that I can pass around to parts of a tax calculator. 理想情况下,我希望有三个自变量可以传递给税率计算器的各个部分。 But I would want to be able to pass around each attribute in the self string individually. 但是我希望能够单独传递自身字符串中的每个属性。 Right now I have this: 现在我有这个:

class taxReturn:

    def __init__(self): 

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

Each attribute would have to be set to a default value that could be passed around, but then later filled in with actual data. 每个属性都必须设置为可以传递的默认值,但随后要用实际数据填充。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

Why not just define this in the __init__ method? 为什么不只在__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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM