Understanding subclasses in python -


i quite new python , have been watching tutorials online because want work on project using python open source library found.

i know possible inheritance in python this

class parent:     def print(self):         pass  class child(parent):     def print(self):         pass 

however when looking @ code in open source library saw this.

from pyalgotrade import strategy pyalgotrade.barfeed import yahoofeed   class mystrategy(strategy.backtestingstrategy):     def __init__(self, feed, instrument):         strategy.backtestingstrategy.__init__(self, feed)         self.__instrument = instrument 

looking @ piece of code wondering class mystrategy(strategy.backtestingstrategy) imply. understand if said strategy in there because mean mystrategy class inherting strategy. not understand linestrategy.backtestingstrategy.__init__(self, feed) implying?

i appreciate explanation.

strategy module imported with:

from pyalgotrade import strategy 

now strategy.backtestingstrategy class located inside module strategy. class used superclass mystrategy.


def __init__(self, feed, instrument):     strategy.backtestingstrategy.__init__(self, feed)     # ... 

this function __init__(self, feed, instrument) constructor function of mystrategy called whenever create new instance of class.

it overrides __init__ method of superclass, still wants execute old code. therefore calls superclass' constructor method using

strategy.backtestingstrategy.__init__(self, feed) 

in line strategy.backtestingstrategy superclass , __init__ constructor method. pass argument self containing current object instance first argument explicitly, because method gets called superclass directly , not instance of it.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -