Connecting Tech Pros Worldwide Forums | Help | Site Map

log files

Newbie
 
Join Date: Oct 2008
Posts: 5
#1: Oct 7 '08
I have this code here
import string
def count_and_sort():
filer = {}
f = open("loggfil.txt","r")
f2 = open("lab5.out","w")
person = "lisa.sm.luth.se"
while True:
rad = f.readline()
split = string.split(rad)
if rad == "":
f.close()
break
elif person in rad:
split2 = split[6]
filer[split2] = filer.get(split2,0) + 1
keys = filer.keys()
keys.sort()
for lines in keys:
f2.write(lines+"\n")
f.close()

this code prints out this from a log file
//csee/csn/include/div.cfg
/csee/csn//include/address.html
/csee/csn//include/footmenu.html
/csee/csn//include/links.html
/csee/csn/presentation.html
/csee/csn/research.html

I want it to display on the side of the filename how many times you downloaded it. I put everything in a dictionary but i can only get the keys. How do i get the values. Thanks in advance

bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,564
#2: Oct 8 '08

re: log files


Quote:

Originally Posted by cooolsson

I have this code here

Expand|Select|Wrap|Line Numbers
  1. import string
  2. def count_and_sort():
  3.     filer = {}
  4.     f = open("loggfil.txt","r")
  5.     f2 = open("lab5.out","w")
  6.     person = "lisa.sm.luth.se"
  7.     while True:
  8.             rad = f.readline()
  9.             split = string.split(rad)
  10.             if rad == "":
  11.                 f.close()
  12.                 break
  13.             elif person in rad:
  14.                 split2 = split[6]
  15.                 filer[split2] = filer.get(split2,0) + 1
  16.     keys = filer.keys()
  17.     keys.sort()
  18.     for lines in keys:
  19.         f2.write(lines+"\n")
  20.     f.close()
this code prints out this from a log file
//csee/csn/include/div.cfg
/csee/csn//include/address.html
/csee/csn//include/footmenu.html
/csee/csn//include/links.html
/csee/csn/presentation.html
/csee/csn/research.html

I want it to display on the side of the filename how many times you downloaded it. I put everything in a dictionary but i can only get the keys. How do i get the values. Thanks in advance

Please use code tags around your code!

To write the file name and quantity:
Expand|Select|Wrap|Line Numbers
  1. f2.write("\n".join(["%s %s" % (key, filer[key]) for key in keys]))
Reply