日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/15 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python即时标记_【Python】读书笔记:Python基础教程-项目1-即时标记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

功能:給文本添加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-即时标记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。