Python ValueError:不支持的格式字符';}';使用%字符串格式时
我试图通过使用Python%字符串格式生成一些LaTeX标记。我在字符串中使用命名字段,并为数据使用带有匹配键的字典。但是,我得到了错误Python ValueError:不支持的格式字符';}';使用%字符串格式时,python,string-formatting,Python,String Formatting,我试图通过使用Python%字符串格式生成一些LaTeX标记。我在字符串中使用命名字段,并为数据使用带有匹配键的字典。但是,我得到了错误ValueError:unsupported format character'}。为什么这个代码不起作用 LaTeXentry = '''\\subsection{{%(title)}} \\begin{{itemize}} \\item %(date) \\item %(description) \\item
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,
}
回溯(最近一次呼叫最后一次):
文件“文件目录”,第115行,在
“头衔”:头衔,
ValueError:索引21处不支持格式字符“}”(0x7d)
您必须添加s
就像标准格式中的%s
-因此您需要%(title)s
,%(date)s
,等等。不幸的是,无论出于何种原因,这并没有解决问题。您必须在许多地方添加%(title)s
,%(date)s
,%(description)s
,同样地,%(标题)s
,%(文件名)s
,%(名称)s
。也许你忘了其中一个。非常感谢。我是个白痴,错过了一个隐藏的。幸运的是regex帮我抓住了它!
Traceback (most recent call last):
File "file_directory", line 115, in <module>
"title": title,
ValueError: unsupported format character '}' (0x7d) at index 21