def divide_timedelta(td1, td2):
try:<EOL><INDENT>return td1 / td2<EOL><DEDENT>except TypeError:<EOL><INDENT>return td1.total_seconds() / td2.total_seconds()<EOL><DEDENT>
Get the ratio of two timedeltas

>>> one_day = datetime.timedelta(days=1)
>>> one_hour = datetime.timedelta(hours=1)
>>> divide_timedelta(one_hour, one_day) == 1 / 24
True