python 生成html_python脚本生成html

python脚本生成html

发布时间:2019-07-22 17:40:19编辑:auto阅读(725)

#-*- coding: utf-8 -*-

from pyh import *

CONST_LIST = [ ['1','AAA','100','100','100','300'],

['2','BBB','99','99','99','297'],

['3','CCC','98','98','98','294']]

class ToHTML:

def __init__(self,project = 'TEST', version = 'v1.0'):

self.page = PyH('%s 测试报告' % project)

self.project = project

def tablecss(self, table = None, width = '600'):

table.attributes['cellSpacing'] = 1

table.attributes['cellPadding'] = 1

table.attributes['border'] = 1

table.attributes['borderColor'] = 'green'

table.attributes['width'] = 'width'

def tr_title_css(self, tr = None, color = '#B0C4DE'):

tr.attributes['bgcolor'] = color

def gentitle(self, name):

self.page << div(b('%s测试报告' % name), id = 'mydiv')

self.tableGroup = self.page << table()

self.tablecss(self.tableGroup,width = '600')

title_tr_group = self.tableGroup << tr()

self.tr_title_css(title_tr_group)

title_tr_group.attributes['align'] = 'center'

title_tr_group << td('名次',style = 'width:100')

title_tr_group << td('姓名',style = 'width:100')

title_tr_group << td('语文',style = 'width:100')

title_tr_group << td('数学',style = 'width:100')

title_tr_group << td('英语',style = 'width:100')

title_tr_group << td('总分',style = 'width:100')

self.page << br()

def setcontent(self,unit):

value_tr_unit = self.tableGroup << tr()

for unitOne in unit:

value_tr_unit << td('%s' % unitOne)

def genreport(self, filename = 'report.html'):

self.page << '结束:'

try:

self.page << 'finished'

except:

self.page << 'unfinished'

self.page << br()

self.page.printOut(filename)

# self test

if __name__ == '__main__':

rp = ToHTML('TEST')

rp.gentitle('FORM')

for unit in CONST_LIST:

rp.setcontent(unit)

rp.genreport('form.html')

####################

关键字:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值