Reputation: 87
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
Upvotes: 3
Views: 1763
Reputation: 142909
You have to add s
like in standard formating %s
- so you need %(title)s
, %(date)s
, etc.
Upvotes: 4