简体   繁体   中英

ValueError: unsupported format character '}' when use % string formatting

I'm trying to generate some LaTeX markup by using Python % string formatting. 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 '}' . 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等。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM