Create multiple classes or multiple objects in Python? -


i have following problem , need advice on how solve best technically in python. new programming have advice.

so have following object , should store something. here example:

  1. object 1: cash dividends (they have following properties)

    • exdate (will store list of dates)
    • recorddate (will store list of dates)
    • paydate (will store list of dates)
    • isin (will store list of text)
  2. object 2: stocksplits (they have following prpoerties)

    • stockplitratio (will ration)
    • exdate(list of dates)
    • ...

i have tried solve this:

class cashdividends(object):      def __init__(self, _gross,_net,_isin, _paydate, _exdate, _recorddate, _frequency, _type, _announceddate, _currency):         self.gross = _gross         self.net = _net         self.isin = _isin         self.paydate = _paydate         self.exdate = _exdate         self.recorddate = _recorddate         self.frequency = _frequency         self.type = _type         self.announceddate = _announceddate         self.currency = _currency 

so if have have create class named stockplits , define __init__ function again.

however there way can have 1 class "corporate actions" , have stock splits , cashdividends in there ?

sure can! in python can pass classes other classes. here simple example:

class a():     def __init__(self):         self.x = 0   class b():     def __init__(self):         self.x = 1   class container():     def __init__(self,objects):         self.x = [obj.x obj in objects]  = a() b = b() c = container([a,b])  c.x  [0,1] 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -