O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - adding status code data

First of all, note that this example won't work if you're using a version of Python less than 2.6. If you fall into that category, you'll have to either upgrade your version, or simply pass over this section.

We're going to update our LogProcessor script to report on the collection of HTTP response codes found within the logfile. We'll simply add an additional handler to process the parsed data.

  1. Using logscan-e.py as a base, create logscan-f.py and add the following additional import statement:
    from collections import defaultdict
    
  2. Now, we're going to change the split method of LogProcessor to also include HTTP status code information.
     def split(self, line): """ Split a logfile. Initially, we just want size ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required