gpt4 book ai didi

python - 在 python 中更改字符串格式分隔符

转载 作者:行者123 更新时间:2023-11-28 22:55:46 25 4
gpt4 key购买 nike

我想模板化一些配置文件,但它们与 python 不兼容“这是一个{template}”.format(template='string')格式化

例如。大括号是配置(nginx 配置)的一部分。

你能把分隔符改成别的吗?

例如,'这是一个[模板]'.format(template='string')

最佳答案

解决方法是使用string.Template,记得把所有的$转义 http://docs.python.org/2/library/string.html#template-strings

关于python - 在 python 中更改字符串格式分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16433589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com