Do Nothing objects in Python

· Read in about 1 min · (77 Words)

Here is how I created a simple Do Nothing object in python.

class DoNothing():
    def __getattr__(self, name):
        def k(*a, **b):
            pass
        return k

log = DoNothing()
log.debug("asdfa", 'asdf"')

Now I can still have log.debug() statements throughout the code-base, in case I want them to do nothing.

All I would do is re-assign log to a DoNothing object.

log = DoNothing()

I am sure there are some flaws with which approach, however this all I need for now.