[英]ValueError: unsupported format character '}' when use % string formatting
I'm trying to generate some LaTeX markup by using Python % string formatting. 我正在尝试通过使用Python%字符串格式生成一些LaTeX标记。 I use named fields in the string and use a dictionary with matching keys for the data. 我在字符串中使用命名字段,并使用带有匹配键的数据字典。 However, I get the error ValueError: unsupported format character '}'
. 但是,出现错误ValueError: unsupported format character '}'
。 Why isn't this code working? 为什么此代码不起作用?
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.