Let's take a closer look at this concept. Let's assume for a second that a colleague heard about your nifty log-processing program and wanted to use it to parse his data. The trouble is that he's already tried his hand at solving the problem with standard shell utilities and his import format is slightly different. It's simply a list of file names followed by the file size in bytes.
Using
logscan.py
as a template, create a new file namedlogscan-b.py
. The two files should be exactly the same.Add an additional class directly below
LogProcessor
as follows.class ColumnLogProcessor(LogProcessor): def split(self, line): parts = line.split() return { 'size': int(parts[1]), 'file_requested': parts[0] }
Now, change the line that creates a
LogProcessor
object. Instead, we want it to create aColumnLogProcess
object.call_chain.append(size_check.process) processor = ColumnLogProcessor(call_chain) processor...