Python多图生成html,Python之生成HTML文件

参考:https://blog.csdn.net/reallocing1/article/details/51694967

教程:http://www.runoob.com/html/html-basic.html

在做图像处理时会有结果数据生成,一种好的方法是将结果保存为HTML文件,在文件中插入图片的超链接,就可以在网页中同时显示结果和图片。因此,本文对Python生成HTML的方法做一个总结。

1 简单示例

#coding:utf-8

import webbrowser

#命名生成的html

GEN_HTML = "test.html"

#打开文件,准备写入

f = open(GEN_HTML,'w')

#准备相关变量

str1 = 'my name is :'

str2 = '--zongxp--'

message = """

%s

%s

"""%(str1,str2)

#写入文件

f.write(message)

#关闭文件

f.close()

#运行完自动在网页中显示

webbrowser.open(GEN_HTML,new = 1)

'''

webbrowser.open(url, new=0, autoraise=True)

Display url using the default browser. If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible. If autoraise is True, the window is raised if possible (note that under many window managers this will occur regardless of the setting of this variable).

'''

---------------------------------2019/9/3更新----------------------------

上述介绍的方法是手动生成html文件,实际上在python中有很多模板引擎可以调用,快速生成html文件,具体方法参考《Python之jinja2模板引擎生成HTML》

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值