class Event(object): SIGNAL = 'SIGNAL' ORDER='ORDER' def __init__(self, route, args): self.data = { 'route': route, 'data': args } def __str__(self): return "route: %s\nargs: %s" % (self.data['route'], self.data['data']) @property def route(self): return self.data['route'] @property def args(self): """""" return self.data['data'] class SignalEvent(Event): """ 由策略函数产生的交易信号事件。 """ def __init__(self, orders): super(SignalEvent, self).__init__(Event.SIGNAL, orders) @property def orders(self): return self.data['data'] orders={'units':100,'direction':'buy','symbol':'USDJPY'} a=SignalEvent(orders) a a.orders a.args a.route
关于类的继承的一篇比较好的讲解:
https://www.runoob.com/w3cnote/python-super-detail-intro.html