首页 > 解决方案 > 有什么方法可以将零添加到十?

问题描述

所以我正在编写一个自动为 Youtube 视频添加时间戳的程序,我所做的基本上是获取一堆视频并将它们放入一个长视频中,所以我编写了一些代码:

description = open("Description.txt", "r+")
description.truncate(0)
description.write("Timestamps:\n")
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) + "\n")

input("Done... ")

这很成功地写入了时间戳,但任何有助于使这个更简单的帮助都将不胜感激,问题是虽然它像这样写时间戳:“2.1”,它的意思是“2:10”,有什么方法可以指定添加每次时间戳在十位时都为 0?很抱歉,如果答案很简单,我是 python 新手。

标签: pythonpython-3.x

解决方案


我认为如果您希望它们具有这种方式,您将不得不将时间戳存储为字符串。否则,您可以将它们存储为双打并滥用一些不错的旧时模块。第三种方法是编写您自己的数据对象以您想要的方式存储它们。


推荐阅读