yaml 属性值

发布于 2024-09-13 09:46:52 字数 125 浏览 1 评论 0原文

我正在使用 yaml 文件来存储属性和值。但某些值需要附加当前日期。

那么如何在 yaml 文件中输入值,以便 yaml 解析器可以自动识别并替换为

我正在使用 pyyaml 和 python 的当前日期

I am using yaml file to store attribute and value. But some of the values need the current date to be appended.

So how do I enter the value in yaml file, so that yaml parser can automatically recognise and substitute with current date

I am using pyyaml and python

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

表情可笑 2024-09-20 09:46:52

pyyaml 不会自动替换任何内容。只需使用自定义字符串,例如 ${now} 并在解析 yaml 文件后将其替换为当前日期。

例如,

value.replace("${now}", datetime.date.today().isoformat())

其中 value 是从输入文件读取的字符串。

pyyaml does not automatically substitute anything. Just use a custom string e.g. ${now} and replace it with the current date after parsing the yaml file.

For example,

value.replace("${now}", datetime.date.today().isoformat())

where value is a sting read from the input file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文