2
我想模板了一些配置文件,但它們與Python的 "this is a {template}".format(template='string')
格式化更改字符串格式定界符在python
如兼容。大括號是config(nginx config)的一部分。
你可以改變分隔符到別的東西嗎?
例如,'this is a [template]'.format(template='string')
我想模板了一些配置文件,但它們與Python的 "this is a {template}".format(template='string')
格式化更改字符串格式定界符在python
如兼容。大括號是config(nginx config)的一部分。
你可以改變分隔符到別的東西嗎?
例如,'this is a [template]'.format(template='string')
的解決方案是使用string.Template
,記得逃脫一切$
的 http://docs.python.org/2/library/string.html#template-strings
AFAIK,這不是不可能覆蓋format()方法。 – 2013-05-08 05:59:15
**另請參閱:** https://stackoverflow.com/questions/35574349/python-format-string-with-custom-delimiters – dreftymac 2017-10-29 09:32:19