::-- JinQing [2008-04-16 02:13:30]
21.2. Strategies for Parsing Text in Python
21.2. 用Python解析文本的策略
In the grand scheme of things, there are a variety of ways to handle text processing in Python:
从整体看,Python处理文本有多种方式:
- Built-in string object expressions
- 内置的字符串对象表达式
- String object method calls
- 字符串对象方法调用
- Regular expression matching
- 正则表达式匹配
- Parser-generator integrations
- 解析器生成器集成
- Handcoded and generated parsers
- 手工编码的和自动生成的解析器
- Running Python code with eval and exec built-ins
- 用内置的eval和exec运行Python代码
For simpler tasks, Python's built-in string object is often all we really need. Python strings can be indexed, concatenated, sliced, and processed with both string method calls and built-in functions. Our emphasis in this chapter, though, is on higher-level tools and techniques for analyzing textual information. Let's briefly explore each of the other approaches with representative examples.
对于较简单的任务,我们往往只需Python内置的字符串对象。 Python的字符串可以进行索引、拼接、切片,并且可用字符串方法和内置函数进行处理。然而,本章的重点是,分析文本信息的高级工具和技术。让我们以代表性的例子,简要地探索各种方法。