Python: How to get the sum of timedelta?
Eg. I just got a lot of timedelta object, and now I want the sum. That\'s it!
(Edit: Assuming that by "sum timedelta" you mean "convert a timedelta to int seconds".)
This is very inefficient, but it is simple:
int((datetime.datetime.fromtimestamp(0) + myTimeDelta).strftime("%s"))
This converts a Unix timestamp (0) into a datetime object, adds your delta to it, and then converts back to a Unix time. Since Unix time counts seconds, this is the number of seconds your timedelta represented.