Python 2.6.5: Divide timedelta with timedelta Python 2.6.5: Divide timedelta with timedelta python python

Python 2.6.5: Divide timedelta with timedelta


In Python ≥2.7, there is a .total_seconds() method to compute the total seconds contained in the timedelta:

>>> down_time.total_seconds() / server_life_period.total_seconds()0.0003779903727652387

Otherwise, there is no way but to compute the total microseconds (for versions < 2.7)

>>> def get_total_seconds(td): return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6... >>> get_total_seconds(down_time) / get_total_seconds(server_life_period)0.0003779903727652387