Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python string.format KeyError

Tags:

python

This question has been answered before, but my string doesn't have any extra curly brackets that would mess up the formatting, so at the moment I'm completely clueless as to why the error

Error is 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)
like image 765
Mojimi Avatar asked Dec 03 '22 13:12

Mojimi


1 Answers

you could do it line by line using a dictionary and passing the dict as keyword arguments using **

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

html = html.format(**d)
like image 124
Jean-François Fabre Avatar answered Dec 27 '22 09:12

Jean-François Fabre