To convert time to a floating point number representing seconds, you can use the total_seconds() method of a timedelta object or the time() function of the time module. Here are two examples:
main.py366 chars12 lines
In the first example, we create a timedelta object representing 1 hour, 30 minutes, and 45 seconds. We then call its total_seconds() method to get the total number of seconds as a float.
In the second example, we create a time object representing 1 hour, 30 minutes, and 45 seconds. We then calculate the total number of seconds as the sum of the hours, minutes, seconds, and fractional seconds (microseconds divided by 1 million).
gistlibby LogSnag