【发布时间】:2012-02-06 14:10:27
【问题描述】:
我有一个 LaTeX 文件,我想用 Python 3 读取并将一个值格式化为结果字符串。比如:
...
\textbf{REPLACE VALUE HERE}
...
但我无法弄清楚如何做到这一点,因为进行字符串格式化的新方法使用 {val} 表示法,并且由于它是一个 LaTeX 文档,因此有大量额外的 {} 字符。
我尝试过类似的方法:
'\textbf{This and that} plus \textbf{{val}}'.format(val='6')
但我明白了
KeyError: 'This and that'
【问题讨论】:
标签: python escaping python-3.x string-formatting