gpt4 book ai didi

python - 值错误: unsupported format character '}' when use % string formatting

转载 作者:行者123 更新时间:2023-12-01 03:42:13 25 4
gpt4 key购买 nike

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

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, %(日期)s

关于python - 值错误: unsupported format character '}' when use % string formatting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39399600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com