0

I need to create an object and define another object's property with that object.

For example, create a class called Income. Then with an Income object, define in a class called taxReturn an attribute called Income.

That way, it'd be possible to access elements of a business's income by doing the following: taxReturn.Income.sal_wge. So far I have this:

class taxReturn:

    def __init__(self, income = None):

        income = income or ['sal_wge', 'intr_rec', 'txexem_intinc', 'divid_AGI', 'qual_divid', 'stinc_txref', 'alimony_rec', 
                 'bus_netprof', 'net_capgain', 'capgain_dist', 'othr_gain', 'IRA_dist', 'pens_annu_rec', 'pens_annu_AGI', 
                 'sch_E_netinc', 'sch_F_netprof', 'unem_comp', 'soc_sec']

        self.income = 'income'

class Income:
   def ('income'):
Gal Grünfeld
  • 800
  • 3
  • 9
  • 32
Alex Durante
  • 71
  • 2
  • 7

1 Answers1

3

There seem to be some code left out in your example, but it's quiet straight forward to create sub-objects, you just instantiate them and assign to a member. Something like:

class Income:
    def __init__(self, sal_wge):
         self.sal_wge = sal_wge

class TaxReturn:
    def __init__(self, income = None):
         self.income = income or Income(sal_wge = 0)

t = TaxReturn()

print(t.income.sal_wge)
skyking
  • 13,817
  • 1
  • 35
  • 57