From: Noel O'B. <bao...@gm...> - 2007-01-30 09:31:27
|
On 30/01/07, Karol Langner <kar...@kn...> wrote: > On Tuesday 30 of January 2007 09:04, Noel O'Boyle wrote: > > Some thoughts: The final conversion of attributes to arrays may be > > different in each case, and so cannot be shared across parsers. Any > > additional shared code, e.g. final progress update, should be called > > from the end of the .parse(), rather than having the user call it. > > Can you give an example of when the conversion of attributes to arrays would > be different between two parsers? I thought the idea was for attributes to be > the same for all parsers. The net effect is the same, but in some cases the attribute is created as an array in the main loop, in others it is built up incremently as a list of lists, and then converted afterwards, outside the loop. Also found outside the loop are instances where if a particular attribute has not been set, it is set to a default value. But after thinking a bit, I guess you're right, the conversion code at least can be moved into a common function. If moenergies is already an array, and you try to convert it, it doesn't cause any harm. > As to calling the function(s) I'm proposing, I wasn't thinking exactly what > you said - calling them from the beginning/end of .parse(). The user sees no > changes here. > > I have however, a different idea. What if .parse() were defined for the > generic class LogFile, and it did all the "generic" things, and also called > self.extract(), which would contain the "for line in self.inputfile" loop > that is specific to each parser (effectively replacing the current.parse()). > This way, we would have only one function more and all the benifits, and > again no change for the user. Indeed, I prefer this too. Noel |