繁体   English   中英

ValueError:使用%字符串格式时不支持的格式字符'}'

[英]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那样添加s因此您需要%(title)s%(date)s等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM