473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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
Oct 7 '08 #1
1 1138
bvdet
2,851 Expert Mod 2GB
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]))
Oct 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
11
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
0
by: wal | last post by:
How does one attach files to emails using libgmail? The following code http://pramode.net/articles/lfy/fuse/4.txt works fine when said files are simple text files, but it failes as soon as the...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.