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:
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)
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
Post a Comment