diveintopython.pdf


Preview of PDF document diveintopython.pdf

Page 1 234327

Text preview


Table of Contents
Chapter 5. Objects and Object−Orientation
5.8. Introducing Class Attributes........................................................................................................................60
5.9. Private Functions.........................................................................................................................................62
5.10. Summary....................................................................................................................................................63
Chapter 6. Exceptions and File Handling....................................................................................................................64
6.1. Handling Exceptions....................................................................................................................................64
6.2. Working with File Objects...........................................................................................................................66
6.3. Iterating with for Loops...............................................................................................................................70
6.4. Using sys.modules.......................................................................................................................................72
6.5. Working with Directories............................................................................................................................74
6.6. Putting It All Together.................................................................................................................................77
6.7. Summary......................................................................................................................................................78
Chapter 7. Regular Expressions...................................................................................................................................81
7.1. Diving In......................................................................................................................................................81
7.2. Case Study: Street Addresses.......................................................................................................................81
7.3. Case Study: Roman Numerals.....................................................................................................................83
7.4. Using the {n,m} Syntax...............................................................................................................................85
7.5. Verbose Regular Expressions......................................................................................................................88
7.6. Case study: Parsing Phone Numbers...........................................................................................................89
7.7. Summary......................................................................................................................................................93
Chapter 8. HTML Processing.......................................................................................................................................94
8.1. Diving in......................................................................................................................................................94
8.2. Introducing sgmllib.py.................................................................................................................................98
8.3. Extracting data from HTML documents....................................................................................................100
8.4. Introducing BaseHTMLProcessor.py........................................................................................................102
8.5. locals and globals.......................................................................................................................................104
8.6. Dictionary−based string formatting...........................................................................................................107
8.7. Quoting attribute values.............................................................................................................................108
8.8. Introducing dialect.py................................................................................................................................109
8.9. Putting it all together..................................................................................................................................111
8.10. Summary..................................................................................................................................................113
Chapter 9. XML Processing........................................................................................................................................115
9.1. Diving in....................................................................................................................................................115
9.2. Packages.....................................................................................................................................................121
9.3. Parsing XML..............................................................................................................................................123
9.4. Unicode......................................................................................................................................................125
9.5. Searching for elements...............................................................................................................................129
9.6. Accessing element attributes......................................................................................................................131
9.7. Segue..........................................................................................................................................................132
Chapter 10. Scripts and Streams................................................................................................................................133
10.1. Abstracting input sources.........................................................................................................................133
10.2. Standard input, output, and error.............................................................................................................136
10.3. Caching node lookups..............................................................................................................................140
10.4. Finding direct children of a node.............................................................................................................141
10.5. Creating separate handlers by node type.................................................................................................141
Dive Into Python

ii