I am facing some error while using classes in python 2.7
My class definition is:
class Timer(object):
def __init__(self):
self.msg = ""
def start(self,msg):
self.msg = msg
self.start = time.time()
def stop(self):
t = time.time() - self.start
return self.msg, " => ", t, 'seconds'
On executing the following code.
timer = Timer()
timer.start("Function 1")
Some code
timer.stop()
timer.start('Function 2')
some code
timer.stop()
I am getting following error:
Function 1 => 0.01 seconds
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object is not callable
For the first call it worked as desired but for the second call, it gave an error. I am unable to figure out the cause of the error.
t = time.time() - self.startlooks wrong.self.startis a function.self.start = time.time()is also wrong