前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python脚本生成html

python脚本生成html

作者头像
py3study
发布2020-01-13 11:19:15
1.3K0
发布2020-01-13 11:19:15
举报
文章被收录于专栏:python3python3

#-*- 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('<b>名次</b>',style = 'width:100')         title_tr_group << td('<b>姓名</b>',style = 'width:100')         title_tr_group << td('<b>语文</b>',style = 'width:100')         title_tr_group << td('<b>数学</b>',style = 'width:100')         title_tr_group << td('<b>英语</b>',style = 'width:100')         title_tr_group << td('<b>总分</b>',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')

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档