When you do the math, you can see that the number "25.05555556" which corresponds to "601:20" hours is expressed in days.
The class datetime.timedelta
do Python can accept entry in days, such as float, and do the accounts for seconds - automatically (or you can only do some divisions). From the total seconds it is easy to get the amounts of hours, minutes and seconds using the operator //
entire division)
import datetime
period = datetime.timdelta(days=25.0555556)
hours = period.total_seconds() // 3600
minutes = (period.total_seconds() % 3600) // 60
seconds = (period.total_seconds() % 60)
final = f"{hours}:{minutes}:{seconds}"
If in your reading the "25..." is coming as a string
with a "," instead of "." the quickest way is to use
the method replace
of the string to exchange the ,
for .
before
to convert the value to numeric with float
-
but if it goes to an app that will stay in production and can
work files formatted otherwise, can be
most interesting to use the module locale
for
always make the replacement the right way - check out the answer here: How to use Python comma instead of a dot
Welcome to [en.so]! You have posted an image of the code and/or error message. Although it sounds like a good idea, it’s not! One of the reasons is that if someone wants to answer the question, they can’t copy the code and change something inside. Click on the [Edit] link and put the code/error as text. See more about this in these links - Manual on how NOT to ask questions, Post Error Message as Picture
– Lucas
Okay, as I can’t describe by the fact that I can’t manipulate the file, I decided to take the image.
– Valdecir Renkaveski