文本处理服务¶
本章介绍的模块提供了广泛的字符串操作和其他文本处理服务。
在 二进制数据服务 之下描述的 codecs 模块也与文本处理高度相关。 此外也请参阅 Python 内置字符串类型的文档 文本序列类型 --- str。
string--- 常见的字符串操作re--- 正则表达式操作difflib--- 计算差异的辅助工具DifferHtmlDiffcontext_diff()get_close_matches()ndiff()restore()unified_diff()diff_bytes()IS_LINE_JUNK()IS_CHARACTER_JUNK()- SequenceMatcher 对象
SequenceMatcherSequenceMatcher.set_seqs()SequenceMatcher.set_seq1()SequenceMatcher.set_seq2()SequenceMatcher.find_longest_match()SequenceMatcher.get_matching_blocks()SequenceMatcher.get_opcodes()SequenceMatcher.get_grouped_opcodes()SequenceMatcher.ratio()SequenceMatcher.quick_ratio()SequenceMatcher.real_quick_ratio()
- SequenceMatcher 的示例
- Differ 对象
- Differ 示例
- difflib 的命令行接口
- ndiff 示例
textwrap--- 文本自动换行与填充wrap()fill()shorten()dedent()indent()TextWrapperTextWrapper.widthTextWrapper.expand_tabsTextWrapper.tabsizeTextWrapper.replace_whitespaceTextWrapper.drop_whitespaceTextWrapper.initial_indentTextWrapper.subsequent_indentTextWrapper.fix_sentence_endingsTextWrapper.break_long_wordsTextWrapper.break_on_hyphensTextWrapper.max_linesTextWrapper.placeholderTextWrapper.wrap()TextWrapper.fill()
unicodedata--- Unicode 数据库stringprep--- 因特网字符串预备readline--- GNU readline 接口rlcompleter--- GNU readline 的补全函数