[Tutor] Confused about lists...
Fri, 23 Feb 2001 02:11:11 -0600 (CST)
I seem to be having a bit of trouble with a VERY simple routine.
I guess I simply do not understand list's. Here is my code snipit then my
# Read in the maillog file
f = open("/var/log/maillog", "r")
# Read the entire maillog as opposed to line by line
for i in f.readlines():
# Use a simple if to see if field 4 contains the word 'open-sytems'
if i == 'open-sytems':
# If the 4th field matches the above increase f by 1
f += 1
# Print f which tells us how many occurences of 'open-systems' are in the
# log in field 4
# Close the file
Feb 23 00:35:09 open-systems postfix/cleanup: A11D516C: message-id=<email@example.com>
I didnt wrap this line so it appears as it does in the log.
What I was TRYING to do is get the above code to read a maillog and count
the ammount of times 'open-systems' appears in the 4th field. I am trying
to write a simple parser for a maillog to count things like total messages
received/sent, connections/day, total time spent on connections, etc..
I had 'f +=1' and 'print f' changed to use i instead of f. But that
printed out TWICE as many lines as it should have. It seems to be just
counting the lines in the log file ignoring my i == 'open-systems'
line. 5 lines of code and apparently I only know how open and close work
for SURE. heh. Any pointers? And any pointers to some good doc's on lists
and loops? I appreciate the advice.