gpt4 book ai didi

Python string.format 键错误

转载 作者:太空狗 更新时间:2023-10-30 01:42:36 25 4
gpt4 key购买 nike

这个问题之前已经回答过,但是我的字符串没有任何额外的大括号会弄乱格式,所以现在我完全不知道为什么会出错

错误是KeyError:内容

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)

最佳答案

您可以使用字典逐行完成,并使用 **

将字典作为关键字参数传递
d=dict()
d['model']=model
d['content']=data
d['theaders']=theaders

html = html.format(**d)

关于Python string.format 键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41229676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com