gpt4 book ai didi

python - 从 Python 字典生成 HTML 表格

转载 作者:IT王子 更新时间:2023-10-29 01:09:57 27 4
gpt4 key购买 nike

我如何将下面的字典转换成 html 表格

  {'Retry': ['30', '12', '12'] 'Station MAC': ['aabbccddeea', 'ffgghhiijj', 'kkllmmnnoo'] Download': ['70.', '99', '90'] }

我要实现的Html表格格式是

Retry       MAC         Download
30 aabbccddee 70
12 ffgghhiijj 99
12 kkllmmnnoo 90

我已经为带有边框和所有内容的表格编写了 CSS,但数据未正确填充。我正在用 web2py 尝试这个。但是发现很难编写逻辑以表格格式打印上面的字典。

谢谢!

最佳答案

您可以使用 web2py TABLETR 帮助程序使它变得更容易一些:

在 Controller 中:

def myfunc():
d = {'Retry': ['30', '12', '12'],
'Station MAC': ['aabbccddeea', 'ffgghhiijj', 'kkllmmnnoo'],
'Download': ['70.', '99', '90']}
colnames = ['Retry', 'Station MAC', 'Download']
rows = zip(*[d[c] for c in colnames])
return dict(rows=rows, colnames=colnames)

在 View 中:

{{=TABLE(THEAD(TR([TH(c) for c in colnames])),
[TR(row) for row in rows]))}}

关于python - 从 Python 字典生成 HTML 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22874058/

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