简体   繁体   English

使用格式化程序模块的简单实用示例是什么?

[英]What is the simple and practical example for using formatter module?

I found a formatter module in Python 3.4 (Lib/formatter.py). 我在Python 3.4(Lib / formatter.py)中找到了一个格式化程序模块。 I can import it. 我可以导入它。

import formatter

Then what? 那呢 What is the purpose of this module? 该模块的目的是什么? There is no unit test for this module so I can not find any examples. 该模块没有单元测试,因此我找不到任何示例。 The documentation is very cryptic. 该文档非常神秘。

"""Generic output formatting.

Formatter objects transform an abstract flow of formatting events into
specific output events on writer objects..........
"""

Is there any simple and practical example for using this module? 有使用该模块的简单实用示例吗? I want to know the purpose of this module. 我想知道这个模块的目的。 Thx. 谢谢。

The module defines an abstract class interface for use with the htmllib.HTMLParser . 该模块定义了一个用于htmllib.HTMLParser的抽象类接口。 That module was removed from Python 3; 该模块已从Python 3中删除; the fact that the formatter module is still there is likely an oversight. formatter模块仍然存在的事实很可能被忽略了。

Use it to turn HTML tree events into formatted documents. 使用它可以将HTML树事件转换为格式化的文档。 For example, if during parsing a HTML document a <H1> header is encountered, the formatter.end_paragraph() method will be called, followed by a formatter.push_font() method call. 例如,如果在解析HTML文档期间遇到<H1>标头,则将调用formatter.end_paragraph()方法 ,然后调用formatter.push_font()方法

Use this module if you are transforming HTML documents; 如果要转换HTML文档,请使用此模块。 like building a HTML-to-plaintext converter, or a web browser. 例如构建HTML到纯文本转换器或Web浏览器。

If you are still confused or unsure about the formatter module, then there is a very good resource which explains it with simple terminology and good examples over here: 如果您仍然对格式化程序模块感到困惑或不确定,那么这里有一个很好的资源,它用简单的术语和很好的示例对其进行了解释:

http://effbot.org/librarybook/formatter.htm http://effbot.org/librarybook/formatter.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM