Q:

Subtracting two datetime.datetime.now().time() objects

I'm trying to build a chronometer with Python, but I'm having trouble subtracting times.
This is what I'm doing:
start = datetime.datetime.now().time()
end = datetime.datetime.now().time()
delta = end - start

And this is the error I'm getting:
TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'

I've looked around and saw some people solving this problem with datetime.combine, but when I try to do it I get this error:
AttributeError: module 'datetime' has no attribute 'combine'

A:

You might instead consider using the time module, this will return the UNIX time in seconds so you can easily find the difference between two times in seconds, you could then convert this to a time string format if desired.
import time
start = time.time()
time.sleep(1)
end = time.time()
delta = end - start

Or still using datetime you can remove the .time() call in your code
start = datetime.datetime.now()
time.sleep(1)
end = datetime.datetime.now()
delta = end - start

This returns a timedelta object which has properties such as .days, .seconds, .microseconds which you can use to extract the different time parts of the difference.

