assuming the following code:
from datetime import datetime
start_time = datetime.now()
end_time = datetime.now()
delta = end_time - start_time
delta_ms = delta.microseconds
what is the most elegant way to simplify the conversion of the timedelta object to mins,secs and millisecs?
The one-liner I have below, requires two calculations of divmod(delta_ms,1000)
, is there any way, keeping it to one line, that it only needs to be calculated once?
mins,secs,ms = divmod(divmod(delta_ms,1000),60) + (divmod(delta_ms,1000)[1],)
I also have the following, which is two lines of code but only calculates divmod(delta_ms,1000)
once:
unwrap = lambda x: divmod(x[0],60) + (x[1],)
mins,secs,ms = unwrap(divmod(delta_ms,1000))