Specto - 9 months ago 44

Python Question

I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds. Is there an easy way to convert the seconds to this format in python?

Answer

By using the `divmod()`

function, which does only a single division to produce both the quotient and the remainder, you can have the result very quickly with only two mathematical operations:

```
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print "%d:%02d:%02d" % (h, m, s)
```