功能:给文本添加HTML标记,使得到的文档能够在浏览器中显示并能作为一个网页使用。

要求:

输入不应包含人工代码或标签;

应能处理不同的块,比如标题、段落、列表项、内嵌文本(比如被强调的文本、URL等);

具有可拓展性。

涉及到的知识点:(参见《Python基础教程 第2版》)

要对文件进行读写(11章),或者至少从标准输入(sys.stdin)读取,用print输出

需要对所有输入的行进行迭代(11章)

需要一些字符串方法(3章)

需要一个或两个生成器(9章)

可能还需要re模块(10章)

测试文档:【text_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 of the company

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

concept was to ride the dot-com wave and 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 interesting web pages:

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).

文本块生成器:【url.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

import 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 ''

else:

print '

'

print block

print '

'

print ''

执行:

python simple_markup.py text_output.html

输出:【text_output.html】

...

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 of the company

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

concept was to ride the dot-com wave and 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 interesting 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/whyeatit)

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).

python即时标记_【Python】读书笔记:Python基础教程-项目1-即时标记相关推荐

  1. 【Python】读书笔记:Python基础教程-项目1-即时标记

    功能:给文本添加HTML标记,使得到的文档能够在浏览器中显示并能作为一个网页使用. 要求: 输入不应包含人工代码或标签: 应能处理不同的块,比如标题.段落.列表项.内嵌文本(比如被强调的文本.URL等 ...

  2. 【读书笔记】 《流畅的python》2.7-2.8 读书笔记

    2021-09-02 <流畅的python>2.7-2.8 读书笔记 一.list.sort方法和内置函数sorted list.sort 方法会就地排序列表,也就是说不会把原列表复制一份 ...

  3. 查看Python的版本_查看当前安装Python的版本

    一.查看Python的版本_查看当前安装Python的版本 具体方法: 首先按[win+r]组合键打开运行: 然后输入cmd,点击[确定]: 最后执行[python --version]命令即可. 特 ...

  4. 【笔记】Python学习(廖雪峰)笔记①——Python基础知识

    Python学习(廖雪峰)笔记①--Python基础知识 Python 基础知识 字符串与编码 ASCII.Unicode.UTF-8 Python字符串 格式化 使用list和tuple list( ...

  5. html5教程 w3cschool,W3Cschool学习笔记——HTML5基础教程

    HTML5 建立的一些规则:新特性应该基于 HTML.CSS.DOM 以及 JavaScript. 减少对外部插件的需求(比如 Flash) 更优秀的错误处理 更多取代脚本的标记 HTML5 应该独立 ...

  6. Practical Python and OpenCV 3rd Edition读书笔记_Chapter8_Smoothing and Blurring平滑与模糊_思维导图

    <Practical Python and OpenCV 3rd Edition>真的是一本非常棒的入门书籍. 它也很薄,只有166页,虽然是纯英文的,如果静下心来认真看一两天就可以读完. ...

  7. 《Deep Learning With Python second edition》英文版读书笔记:第十一章DL for text: NLP、Transformer、Seq2Seq

    文章目录 第十一章:Deep learning for text 11.1 Natural language processing: The bird's eye view 11.2 Preparin ...

  8. 读书笔记(python)--图及其算法

    限于笔者技术水平,文章可能存在错漏,请各位不吝赐教,笔者会尽快改正 文章目录 前言 一.图的术语与实现 二.宽度优先(BFS)与深度优先(DFS) 1.一个简单的图 2.BFS代码 3.DFS代码 4 ...

  9. 读书笔记——Python第一个程序Hello world

    2019独角兽企业重金招聘Python工程师标准>>> 开始学习python,随手写那么点笔记 ------------------------------------------- ...

最新文章

  1. linux 内存泄露工具,linux下检查内存泄露的工具--mtrace
  2. 错过618?暑假阅读季不要错过啦!
  3. fitEllipse函数
  4. 思科pix防火墙配置实例大全
  5. Python格式化输出方法
  6. java获取本机ip地址_代码片段:获取系统所有IP
  7. 使用 Gitolite 搭建 Git 服务器
  8. SQL Server差异备份的备份/还原原理
  9. 基于struts2的web系统中的返回功能
  10. MSDP配置(anycast RP)
  11. 计算机关机键 自动重启,我的电脑总是关机后自动重启怎么办?
  12. 虚拟机kali挂主机代理
  13. 病毒木马入侵招数专题
  14. 如何应对项目范围变更管理
  15. 编译原理:语法树,短语,直接短语,句柄
  16. java哪几种运算符_java运算符有哪些
  17. linux sas hba,详谈RAID功能和SAS HBA系列产品
  18. 笔记本电脑计算机乱跳,笔记本屏幕的鼠标指针乱跳解决方法
  19. windows驱动开发3:第一个驱动及调试
  20. Jetson nano 卡刷教程

热门文章

  1. 有一个工程师男(女)朋友是什么样的体验?
  2. 硬核!C语言八大排序算法,附动图和详细代码解释!
  3. 基于FPGA的LED 16×16点阵汉字显示设计
  4. php5.2 get漏洞,ThinkPHP 5.x 远程代码getshell漏洞分析
  5. 为什么grpc不支持php,带入gRPC:让你的服务同时提供 HTTP 接口
  6. 最大均值差异java_MATLAB最大均值差异(Maximum Mean Discrepancy)
  7. mysql+两行+一样+筛选_MySQL计算相邻两行某列差值的方法
  8. Java程序中AB类可调用_19年【石油大学】《Java语言程序设计》二次在线作业(100分)...
  9. C#并发实战Parallel.ForEach使用
  10. 适配器(Adaptor)模式