Book Image

Python 2.6 Text Processing: Beginners Guide

By : Jeff McNeil
Book Image

Python 2.6 Text Processing: Beginners Guide

By: Jeff McNeil

Overview of this book

<p>For programmers, working with text is not about reading their newspaper on a break; it's about taking textual data in one form and doing something to it. Extract, decrypt, parse, restructure – these are just some of the text tasks that can occupy much of a programmer's life. If this is your life, this book will make it better – a practical guide on how to do what you want with textual data in Python.</p> <p><em>Python 2.6 Text Processing Beginner's Guide</em> is the easiest way to learn how to manipulate text with Python. Packed with examples, it will teach you text processing techniques and give you the skills to work with the most popular Python libraries for transforming text from one form to another.</p> <p>The book gets you going with a quick look at some data formats, and installing the supporting libraries and components so that you're ready to get started. You move on to extracting text from a collection of sources and handling it using Python's built-in string functions and regular expressions. You look into processing structured text documents such as XML and HTML, JSON, and CSV. Then you progress to generating documents and creating templates. Finally you look at ways to enhance text output via a collection of third-party packages such as Nucular, PyParsing, NLTK, and Mako.</p>
Table of Contents (20 chapters)
Python 2.6 Text Processing Beginner's Guide
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Chapter 4: Text Processing Using the Standard Library


CSV handling

  1. It's possible to create a subclass of Dialect, or build a new dialect directly via keyword arguments to the register_dialect function of the csv module. It's generally quicker to use the register_dialect approach. However, supporting the former simply means defining a few extra attributes. That's useful if you already have data encapsulated in a class.

  2. Consider a comma-separated value that contains a comma! The split method will return two values here instead of one. This is where the quoting logic within the csv module pays off.

  3. They're not. Formulas are spreadsheet concepts that do not carry over into plain text.

JSON formatting

  1. This is because we read in a text source to begin with and do not perform any integer casting or type conversion.

  2. Generally speaking, no. There are other methods that can be used for Object Serialization, such as the pickle module. Complex structures are not saved out. JSON is usually best suited for data transfer rather than object serialization or marshalling.

  3. Because of its small size. XML includes a lot of markup and tag structure, whereas JSON does not.