log files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cooolsson
    New Member
    • Oct 2008
    • 5

    log files

    I have this code here
    import string
    def count_and_sort( ):
    filer = {}
    f = open("loggfil.t xt","r")
    f2 = open("lab5.out" ,"w")
    person = "lisa.sm.luth.s e"
    while True:
    rad = f.readline()
    split = string.split(ra d)
    if rad == "":
    f.close()
    break
    elif person in rad:
    split2 = split[6]
    filer[split2] = filer.get(split 2,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.ht ml
    /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
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by cooolsson
    I have this code here
    Code:
    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.ht ml
    /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:
    Code:
    f2.write("\n".join(["%s %s" % (key, filer[key]) for key in keys]))

    Comment

    Working...