【发布时间】:2021-07-12 16:27:19
【问题描述】:
我在配置文件中有以下模板:
"template": "2.1/files/{year:04d}/{month:02d}/{day:02d}/{hour:02d}"
我想根据函数的输入来填写年、月、日和小时。到目前为止,我已经尝试过:
test_fill = prefix.format(2021,12,23,14)
其中前缀具有上述模板字符串。尝试以上我得到:
KeyError: 'year'
根据我对函数的年、月、日和小时输入来修改字符串的正确方法是什么?
【问题讨论】:
标签: python string config keyerror