Connecting Tech Pros Worldwide Help | Site Map

log files

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 7th, 2008, 10:18 PM
Newbie
 
Join Date: Oct 2008
Posts: 5
Default log files

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
Reply
  #2  
Old October 8th, 2008, 02:52 AM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,439
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.