简体   繁体   English

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

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

相关问题 使用字符串格式时不支持的格式字符 - Unsupported format character when using string formatting 格式化字符串时出错-ValueError:不支持的格式字符&#39;,&#39;(0x2c) - Error when formatting a String - ValueError: unsupported format character ',' (0x2c) ValueError:使用dict格式化时,格式字符\\&#39;“ \\&#39;(0x22)不支持 - ValueError: unsupported format character \'"\' (0x22) when formatting with dict 使用%字符串格式时,值错误不受支持的格式字符““” - Value Error unsupported format character '"' when using % string formatting ValueError:不支持的格式字符&#39; - ValueError: unsupported format character ' “ValueError: Unsupported format character &#39; ” &#39; (0x22) at...&quot; in Python / String - “ValueError: Unsupported format character ' ” ' (0x22) at…" in Python / String ValueError:日期/时间格式字符串中不支持的字符“:”用于记录 - ValueError: Unsupported character ':' in date/time format string for logging python关键字字符串格式与&#39;%&#39;混淆错误:不支持的格式字符&#39;p&#39; - python keyword string formatting with '%' confusing error : unsupported format character 'p' ValueError:mysql scrapy pipline中不支持的格式字符 - ValueError: unsupported format character in mysql scrapy pipline ValueError:形成字符串时不支持的格式字符 - ValueError: unsupported format character while forming strings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM