Python 创建 html 格式的报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4804510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create an html formatted report
提问by VacuumTube
I have a Python 2.6 app running on Linux that creates a CSV file. From the app, I need to create an HTML report, as a single HTML file, that presents the data from the CSV (probably as a table) and also highlights fields where the values meet certain criteria. Charting type functionality would be a nice to have.
我有一个在 Linux 上运行的 Python 2.6 应用程序,它创建了一个 CSV 文件。在应用程序中,我需要创建一个 HTML 报告,作为单个 HTML 文件,它显示来自 CSV 的数据(可能作为表格),并突出显示值满足特定条件的字段。图表类型功能会很好。
What's the best way to do this?
做到这一点的最佳方法是什么?
No GPL stuff please.
请不要使用 GPL 内容。
采纳答案by chris
Choose a Python csv library from here. Now that you have the data mapped to Python data structures you can iterate on it and create the html. I would use the Jinja2templating engine which is nicely documented. Highlighting rows/cells would work by setting certain css classes on the respective tr/td elements in the table.
从这里选择一个 Python csv 库。现在您已将数据映射到 Python 数据结构,您可以对其进行迭代并创建 html。我会使用有很好记录的Jinja2模板引擎。突出显示行/单元格可以通过在表中相应的 tr/td 元素上设置某些 css 类来工作。

