Skip to content Skip to sidebar Skip to footer

Timing Decorator Is Raising "'nonetype' Object Is Not Callable" Exception

I have i timing function and my main function. When i use only main function it runs fine, but when i use timing function as a decorator it raises an exception. Timing function cod

Solution 1:

The decorator needs to return the decorated function:

def timing(function):
  def wrapped():
    import time
    t = time.time()
    function()
    t = time.time() - t
    print('Program has been running for {} seconds.'.format(t))
  return wrapped

@timing
def main():
  # some code

Post a Comment for "Timing Decorator Is Raising "'nonetype' Object Is Not Callable" Exception"