更改python中的字符串格式分隔符

2024-03-10

我想模板化一些配置文件,但它们与 python 不兼容"this is a {template}".format(template='string')格式化

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

您可以将分隔符更改为其他内容吗?

eg, 'this is a [template]'.format(template='string')


解决方案是使用string.Template,并记住逃离所有$'s http://docs.python.org/2/library/string.html#template-strings http://docs.python.org/2/library/string.html#template-strings

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

更改python中的字符串格式分隔符 的相关文章

随机推荐