Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

python - Any Way To Add Zeros to Tens?

So I'm writing a program that automatically timestamps Youtube videos, what I'm doing basically is getting a bunch of videos and putting them in one long video, so I have some code writted:

description = open("Description.txt", "r+")
description.truncate(0)
description.write("Timestamps:
")
timestamps = [0.01, 0.08, 0.16, 0.30, 0.50, 1.05, 1.25] #These are just examples, usually this would be a list of 50 or so values
timeadd = 0
total = 0

for time in timestamps:
    timeadd += 1

for add in range(timeadd):
    total += timestamps[add]
    print(total)
    description.write(str(total) + "
")

input("Done... ")

This works pretty successfully writes timestamps but any help to make this simpler would be appreciated, the problem is though it writes Timestamps like this: "2.1", what it means is "2:10", is there any way I could specify to add a 0 every time the Timestamp is in the tens place? I'm sorry if the answer is simple, I'm new to python.

question from:https://stackoverflow.com/questions/65930754/any-way-to-add-zeros-to-tens

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you are going to have to store the timestamps as strings, if you want them to have this way. Ootherwise, you can store them as doubles and abuse a bit good ol' time module. Third way would be to write your own data object to store them the way you want.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...