def timedelta_float(td, units='days'):
    """
    Returns a float of timedelta TD in UNITS
    (either 'days' or 'seconds').

    Can be negative for things in the past.
    
    timedelta returns the number of
    days and the number of seconds, but you have to combine
    them to get a float timedelta.

    e.g. timedelta_float(now() - dt_last_week) == c. 7.0
    """
    # 86400 = number of seconds in a day
    if units == 'days':
        return td.days + td.seconds / 86400.0
    elif units == 'seconds':
        return td.days*86400.0 + td.seconds
    else:
        raise Exception('Unknown units %s' % units)