Best way to read, and analyze a log file?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Aug 1 13:22:23 EDT 2006


superflit at gmail.com:

> 1- Read the data and put all variables in a list
> 2- Read the data and put all the variables in dictionary?
> the logs is in this format
> xxxxxxxxxxxxxxxxxxxxxxxxxx
> The separation is by byte size like
> xxx three bytes for code x , xxxx bytes for hour, etc..
> I have two main objectives.
> Show all data to user.
> Analyze the data: like total sum, average,etc..

If you want to do all by yourself you can create a list of starting
positions, and you can add None to it, so you can use it to slice a
line with a loop.
You can also create a list of types, so you can cast the string parts
to their correct types, catching the exceptions. You can do it in a
second loop for clarity, or the first one to speed up a bit.
So you can just create a list of data for each input line, a dict may
be unnecessary because the number of fields seems fixed.

Bye,
bearophile




More information about the Python-list mailing list