Creating a dictionary from log file records

Sean 'Shaleh' Perry shaleh at valinux.com
Fri Feb 16 11:35:52 EST 2001


On 16-Feb-2001 Roy.Culley at switzerland.org wrote:
> I'm new to python and am trying to convert a perl script which analyses
> firewall logs to python as a learning exercise.
> 
> The log files contain lines of multiple key / value pairs such as:
> 
>     interface qfe0 proto tcp src 1.1.1.1 dst 2.2.2.2 service smtp \
>         s_port 44008 len 44 rule 7
> 
> Not all records are the same and the key / value pairs are not at
> fixed positions. In perl, assuming the line is in $_, I can do:
> 
>     %Rec = split
> 
> Is there an equivalent simple way to do this with python? I've done
> it by converting the data into a list and using a while loop to set
> the dictionary entries. However, the log files have about 4 million
> entries per day so I need something that is fast.
> 

so for every line in the file, you create a temporary perl hash.  What do you
do with the hash?  generating a new hash for every line can not be but so fast.




More information about the Python-list mailing list