[英]Need to Create Class with Default Values for Attributes
我需要創建一個將稅收數據存儲為默認值的類,但可以使用來自納稅申報單的實際數據填充該類。 例如,假設我有三類:收入,法定調整和稅額計算,每一個包含幾個屬性。 理想情況下,我希望有三個自變量可以傳遞給稅率計算器的各個部分。 但是我希望能夠單獨傳遞自身字符串中的每個屬性。 現在我有這個:
class taxReturn:
def __init__(self):
self.income = [attribute1, attribute2, attribute3]
self.statut = [attribute4, attribute5, attribute6]
self.tax_comp = [attribute7, attribute8, attribute9]
每個屬性都必須設置為可以傳遞的默認值,但隨后要用實際數據填充。
任何幫助,將不勝感激。 謝謝!
為什么不只在__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.