Python string.format KeyError

This question has already been given, but in my line there are no extra curly braces that would ruin the formatting, so at the moment I absolutely do not know why the error

Error: KeyError: content

html = """
    <table class=\"ui celled compact table\" model=\"{model}\">
        {theaders}
        <tbody>
            {content}
        </tbody>
    </table>
    """
html = html.format(model=model)
html = html.format(content=data)
html = html.format(theaders=theaders)
+4
source share
2 answers

you can do this line by line using a dictionary and passing dict arguments as a keyword using **

d=dict()
d['model']=model
d['content']=data
d['theaders']=theaders

html = html.format(**d)
+10
source

you need to fill in the values ​​at a time:

html.format(model=model, content=data, theaders=theaders)
+7
source

Source: https://habr.com/ru/post/1664209/


All Articles