[英]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.