|
Size: 1824
Comment:
|
← Revision 4 as of 2009-12-25 07:13:57 ⇥
Size: 1806
Comment: converted to 1.6 markup
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 4: | Line 4: |
| ::-- JinQing [[[DateTime(2008-04-16T02:13:30Z)]]] [[BR]][[BR]] |
::-- JinQing [<<DateTime(2008-04-16T02:13:30Z)>>] <<BR>><<BR>> |
| Line 8: | Line 8: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 11: | Line 11: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 14: | Line 14: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 17: | Line 17: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 56: | Line 56: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 58: | Line 58: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 61: | Line 61: |
| [[BR]][[BR]] | <<BR>><<BR>> |
| Line 65: | Line 65: |
| [[PageComment2]] |
::-- 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的字符串可以进行索引、拼接、切片,并且可用字符串方法和内置函数进行处理。然而,本章的重点是,分析文本信息的高级工具和技术。让我们以代表性的例子,简要地探索各种方法。
