实例txt文件test_input.txt:

Welcome to World Wide Spam. Inc.

These are the corporate web pages of *World Wide Spam*,Inc.We hope

you find your stay enjoyable,and that you will sample many of our

products.

A short history if the company

World Wide Spam was started in the summer of 2000.The business

concept was to ride the dot-com wave ande to make money both through

bulk email and by selling canned meat online.

After receiving several complaints from customers who weren't

satisfied by their bulk email.World Wide Spam altered their profile,

and focused 100%on canned goods.Today,they rank as the world's

13,892nd online supplier of SPAM.

Destinations

From this page you may visit several of our intersting web pages:

-What is SPAM?(http://wwspam.fu/whatisspam)

-How do they make it?(http://wwspam.fu/howtomakeit)

-Why should I eat it?(http://wwspam.fu/whyeatif)

How to get in touch with us

You can get in touch with us in *many* ways: By phone (555-1234),by

email (wwspam@wwspam.fu) or by visiting our customer feedback page

(http://wwspam.fu/feedback).

将txt文件分块的模块util.py:

def lines(file):

for line in file:yield line

yield '\n'

def blocks(file):

block = []

for line in lines(file):

if line.strip():

block.append(line)

elif block:

yield ''.join(block).strip()

block=[]

简单的转换模块simple_markup.py:

import sys,re

from util import *

print '

'

title = True

for block in blocks(sys.stdin):

block = re.sub(r'\*(.+?)\*',r'\1',block)

if title:

print'

'

print block

print ''

title =False

else:

print'

'

print block

print'

'

print''

转换代码:python simple_markup.py test_output.html

代码执行过后当前目录会产生一个html文件test_output.html,放入浏览器运行可观察效果。

关于代码的注释部分可以参看http://1.imablog.sinaapp.com/exam-translate-txt-html/

python转html_Python 将文本转换成html的简单示例相关推荐

  1. python输出图片到word_python将文本转换成图片输出的方法

    本文实例讲述了python将文本转换成图片输出的方法.分享给大家供大家参考.具体实现方法如下: #-*- coding:utf-8 -*- from PIL import Image,ImageFon ...

  2. html表格转换为csv,python实现将html表格转换成CSV文件的方法

    python实现将html表格转换成CSV文件的方法 发布于 2015-11-18 16:53:39 | 155 次阅读 | 评论: 0 | 来源: 网友投递 Python编程语言Python 是一种 ...

  3. .NET 将文本转换成语音 (转)

    用过金山词霸的都知道金山词霸里有个功能能够将单词按其读音读出来.也许会有人认为它是事先将所有的单词的读音文件存储在数据库里,然后事需要的时候再调用.其实事实上并不是这样,我们有更好的解决办法,MS就专 ...

  4. python动态图片转字符画_使用python实现一个将图片转换成字符画的功能

    使用python实现一个将图片转换成字符画的功能 发布时间:2020-11-05 16:01:25 来源:亿速云 阅读:97 使用python实现一个将图片转换成字符画的功能?针对这个问题,这篇文章详 ...

  5. Word/WPS 文本转换成表格

    Word 文本转换成表格 WPS Word 将文本转换成表格 将表格转换成文本 参考资料 WPS 使用WPS Office打开文档,在文字内容间用统一的标记或符号分隔开. (这里使用英文逗号分开) 选 ...

  6. 用Python批处理将WORD文件转换成PDF格式(工具:win32com模块)

    用Python批处理将WORD文件转换成PDF格式 一.问题分析 key words:批处理.WORD转换PDF.办公自动化 二.材料准备 三.代码实现 ☆其他问题:日常遇到问题,整理笔记不易,欢迎交 ...

  7. typora+pandoc:markdown文本转换成word(也可把word转换成markdown哦)

    因为想把自己写的博客转换成word,博客是markdown格式,公式什么的又懒得在word里面敲第二遍.于是就找了个方法让.md文本与.doc文本转换.反之也可把word转换成markdown哦.教程 ...

  8. Python 将MP3音频文件转换成MIDI乐谱文件

    Python 将MP3音频文件转换成MIDI乐谱文件 spleeter 1.系统环境 我的Python环境 安装spleeter pip install spleeter 查看spleeter是否安装 ...

  9. ffmpeg 将文本转换成音频以及多个音频合成一个音频的方法

    去除文本中多余的无用字符 首先使用strip_tags函数,去除文本中的htm标签.如果有第二个参数,则第二个参数表示运行存在的标签. 第二步可以使用urldecode函数进行编码转换,将URL编码转 ...

  10. EXCEL中用TEXT函数将文本转换成日期

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! EXCE ...

最新文章

  1. 电商企业为什么要搞中台?
  2. 难道这是残差结构的本质(addnorm)
  3. 可变车道怎么走不违章_可变车道怎么才能正确通行?老司机来告诉你什么才是正确的走法。...
  4. 成功解决sklearn\ensemble\weight_boosting.py:29: DeprecationWarning: numpy.core.umath_tests is an interna
  5. 快打开《来自艾泽拉斯的一封密码信》,破译网易重大机密
  6. matlab中evrnd函数_【matlab】Matlab中产生正态分布随机数的函数normrnd
  7. oracle数据库赋权_oracle数据库删除赋权
  8. phpMyAdmin批量修改Mysql数据表前缀的方法
  9. linux下时间编程,Linux下的时间操作编程
  10. Ubuntu16.04安装后开发环境配置和常用软件安装
  11. ajax传递timestamp,解决ajax请求自动增加时间戳问题
  12. unity Scene窗口的任意比例放大和缩小
  13. Excel / WPS 下拉选择数据
  14. 测试专业相机快门软件,检测快门次数软件 快门数量检测
  15. 搭建分布式FastDFS集群
  16. JVm - Parallel Scavenge 垃圾回收器
  17. elementUI级联选择器(Cascader)回显问题和clearCheckedNodes无效的解决方法
  18. BUG记录: Exception evaluating SpringEL expression
  19. ·穷途末路之举·解决VirtualBox启动问题-Error relaunching VirtualBox VM process 5/terminated with exit code1(0x1)
  20. 关于 618的前世今生,我帮东哥告诉你

热门文章

  1. 一切成功源于积累——20140928 认识货币——加元
  2. Android SQLite Google 官方用法
  3. luogu3191 [HNOI2007]紧急疏散EVACUATE
  4. python实现isPrime()函数
  5. 中科大一所学校撑起中国人工智能半壁江山
  6. 不越狱破解A1528 iPhone5s移动联通4G网络
  7. 最优化理论与方法学习笔记01——黄金分割法与进退法求单峰区间Matlab编程实现
  8. 一位女性程序员的职业规划
  9. 笔记本电脑切换Fn功能键
  10. android批量发送短信