[Tutor] newbie string parsing question

Clay Shirky clay at shirky.com
Thu Nov 13 17:07:23 EST 2003

Avoid re if you can

If you are parsing an apache error log, and you have python 2.2.2 or higher,
something like this might work:


for line in file("/usr/local/apache/var/log/error_log"):
    line = line.strip()
    line = line.replace("[", "")
    fields = line.split("]") # needs 2.2.2 or higher
    for entry in fields:
        print entry,

Fields is a list of date, error, client, and message.


 > Hello all,
> I am new to the pyhon game and have been hitting a stone wall with the re
> module. I am trying to parse an app server log, in real time, and want return
> the whole string that contains a value, like "Error".
> Any help would be great....
> Thanks..
> VN
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list