How to use Log/Debug/Error/Quit etc .. in any Python class?

Hi guys,

As the title suggests, in a Python class that does not inherit from QCAlgorithm base class, how should I do debugging?


Update Backtest

I understand that the Debug and Log methods are defined in QCAlgorithm class, therefore I tried the following:

class somerandomclass:
    def __init__(self):
        self.qca = QCAlgorithm()

which does not work. Then I tried making 'somerandomclass' a inheried class:

class somerandomclass(QCAlgorithm):
    def __init__(self):

that does not work either (I tried to create a custom indicator and register it by following the tutorial). It produced error:

SystemError : <bound method 'RegisterIndicator'> returned a result with an error set

Any advice would be appreciated!


Hi Thomas,

You could use the QC method in other classes like this 

class A(object):
def __init__(self, algo):
self.algo = algo

def log_time(self):

When you call the method in the class


Hi  Jing Wu ,

Thanks for the reply. 

In your example, when I construct the object of class A in a top level file (i.e., what should I substitute the 'algo'  in the constructor with? Should I do the following?

obj_A = A(QCAlgorithm)

Thanks for the help!


You need to pass the "self" in basic QCAlgorithm() class to create the instance of the class. Please see this example


Jing Wu , I see. Thanks a lot!


Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed