[英]Can the datetime module in Python be formatted to output double digit numbers?
[英]How to output double digit in python filename
每次打開某個字段的電源時,我都必須更改其他人創建的腳本,該腳本會從 InfluxDB 中提取 csv 文件。 該腳本有效,但現在需要更改它以允許文件 output 具有 exp_00 而不是 exp_0,該腳本的原始創建者不再可供查詢。
通過代碼,我看到了下面的代碼片段作為文件名命名約定,我該如何更改它,所以文件名 output 是 exp_00(兩位數)而不是 exp_0。
if len(dates) == 1 and dates[0][0] == None:
print("No Treatments")
else:
for index, entry in enumerate(dates):
print(entry)
print('*'*20)
print('exp', index)
print('start', entry[0].strftime("%m/%d/%Y, %H:%M:%S"))
print('end', entry[1].strftime("%m/%d/%Y, %H:%M:%S"))
print('duration', str((entry[1]-entry[0]).total_seconds()) + 's')
start = dates[index][0]
end = dates[index][1]
export_experiment_data(index=index, start=start, end=end)
任何幫助深表感謝。
我想通了,這個代碼片段中沒有進行命名。 我只是 .zfill(2) 以兩位數輸出索引變量。 如果沒有增加價值,可以刪除該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.