Studying a log in more detail
A file is the serialized representation for Python objects. In some rare cases, the objects are strings, and we can deserialize the strings from the text file directly. In the case of our web server logs, some of the strings represent a date-time stamp. Also, the size of the transmitted content shouldn't be treated as a string, since it's properly either an integer size or the None
object if nothing was transmitted to the browser.
When requests for analysis come in, we'll often have to convert objects from strings to more useful Python objects. Generally, we're happiest if we simply convert everything into a useful, native Python data structure.
What kind of data structure should we use? We can't continue to use a Match
object: it only knows about strings. We want to work with integers and datetimes.
The first answer is often to create a customized class that will hold the various attributes from a single entry in a log. This gives the...