[英]python to generate html color table output
I am planning write HTML table with color using python script. 我计划使用python脚本用颜色写HTML表。
I got below script in below link and started testing. 我在下面的链接中找到了下面的脚本并开始测试。 Click here 点击这里
from html import HTML
import sys
import os
table_data = [
['Last name', 'First name', 'Age'],
['Smith', 'John', 30],
['Carpenter', 'Jack', 47],
['Johnson', 'Paul', 62],
]
htmlcode = HTML.table(table_data)
f = open("file123.html", 'w')
sys.stdout = f
f.close()
When I execute above code. 当我执行以上代码时。 I am getting below error. 我正在错误以下。
Traceback (most recent call last):
File "c:\Users\bob\Documents\scripts\html\html.py", line 10, in <module>
htmlcode = HTML.table(table_data)
AttributeError: type object 'HTML' has no attribute 'table'.
Is there any easiest way we can create table with color from python script 有什么最简单的方法可以从python脚本创建带有颜色的表
I am using python 2.7 in windows 10 OS. 我在Windows 10 OS中使用python 2.7。
The API documentation of HTML.py states that tables are created like this: t = HTML.Table(header_row=['Test', 'Result'])
replace HTML.table with HTML.Table in your code (like below) HTML.py的API文档指出,表的创建方式如下: t = HTML.Table(header_row=['Test', 'Result'])
用代码中的HTML.Table替换HTML.table(如下所示)
import HTML
import sys
import os
table_data = [
['Last name', 'First name', 'Age'],
['Smith', 'John', 30],
['Carpenter', 'Jack', 47],
['Johnson', 'Paul', 62],
]
htmlcode = HTML.Table(table_data)
f = open("file123.html", 'w')
sys.stdout = f
f.close()
make sure to also install the module correctly as described here : 确保也按照此处所述正确安装模块:
INSTALLATION: 安装:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.