ValueError: unsupported format character '}' when use % string formatting

ValueError: unsupported format character '}' when use % string formatting

我正在尝试使用 Python % 字符串格式生成一些 LaTeX 标记。我在字符串中使用命名字段,并使用带有数据匹配键的字典。但是,我收到错误 ValueError: unsupported format character '}'。为什么此代码不起作用?

LaTeXentry = '''\subsection{{%(title)}}
    \begin{{itemize}}
    \item 
    %(date)
    \item
    %(description)
    \item
    Source:\cite{{%(title)}}
    \item
    filename(s):
    %(filename)
    \item 
    Contributed by %(name)'''

LaTeXcodeToAdd = LaTeXentry % {
    "time" : Timestamp,
    "date" : date,
    "description" : summary, 
    "filename" : filename,
    "name" : name,
    "title": title,
}
Traceback (most recent call last):
  File "file_directory", line 115, in <module>
    "title": title,
ValueError: unsupported format character '}' (0x7d) at index 21

您必须像标准格式 %s 一样添加 s - 因此您需要 %(title)s%(date)s、等等