[Tutor] search through a list

nephish nephish at xit.net
Mon Jul 4 05:12:36 CEST 2005

Hey there, sorry to bother you again about this same problem
but i have a line of code in this same issue that works in idle
but it does not work in a regular script.

that same thing i am trying to do, reading the directory, comparing the 
list of files to a list ..... just want to catch the newest lines of a 
log file to process later.

here is what i have ( kinda long )

# Update Database
import os
print ' '
print ' '

#get a list of log files in the directory

print LogsInDir #testing only, remove later

#read the contents of the log list
LogList = open('/home/nephish/Projects/Piv_CGI/LogList.txt', 'r')
print 'Lines of LogList.txt'
for i in LogsRead:
    print i #testing only, remove later

#this function returns the number of lines on record for each log file.
def line_finder(LogsInDir, flag):
    for line in LogsInDir:
        if return_next:
            return line.strip()
        if line.strip() == flag:
            return_next = True

NumLogsInDir = len(LogsInDir)

NextLog = 0

while NextLog < NumLogsInDir:

    print 'opening file '+LogsInDir[NextLog]
    print ' '
    Count_in_Log = 
open('/home/nephish/Projects/Piv_CGI/logs/'+LogsInDir[NextLog], "r")

    Defer = Count_in_Log.readlines()

    CountEmUp = len(Defer)
    print 'number is '
    print CountEmUp
    NumLinesOnFile=line_finder(LogsRead, LogsInDir[NextLog])
    print NumLinesOnFile
        if CountEmUp > int(NumLinesOnFile):
            print " "+LogsInDir[NextLog]+" is longer than on record"
        XtraLines = int(NumLinesOnFile) - CountEmUp
            print XtraLines
        print ' '+LogsInDir[NextLog]+" is not greater than on record"
            print XtraLines
print 'done' 

the line in question is this one:

NumLinesOnFile=line_finder(LogsRead, LogsInDir[NextLog])
    print NumLinesOnFile

if i run this in idle printing NumLinesOnFile gives me a string 14

when run in a terminal it returns "None"

dont get it. is it because it is in a while loop?

any ideas would be awesome here.

More information about the Tutor mailing list