python - 有什么方法可以将零添加到十?
问题描述
所以我正在编写一个自动为 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 新手。
解决方案
我认为如果您希望它们具有这种方式,您将不得不将时间戳存储为字符串。否则,您可以将它们存储为双打并滥用一些不错的旧时模块。第三种方法是编写您自己的数据对象以您想要的方式存储它们。
推荐阅读
- php - 会话中的复选框表单无法正常工作
- python - Python 循环 - 有效输入
- docker - 为什么 Dockerfile 中的 CMD 格式看起来像一个命令列表?
- flutter - 如何将二维码扫描的结果保存在 json 文件中(用于历史记录)并在另一个小部件中显示相同的结果
- csv - 通过控制文件创建 .csv 文件
- python - 创建一个能够使用 python 脚本读取卷并编译/执行它的 docker 映像
- awk - 如何使用 awk 解析多个文件并将输出放入生成的动态文件中?
- alfresco - 在 Alfresco 5.1 中为作业“ContentStoreCleanerTrigger”和“NodeServiceCleanupTrigger”设置保护天数?
- shell - shell脚本不适用于-z
- docker - 代码在 Dockerfile 中有效,但在 docker-compose.yml 中无效