[Tutor] search through a list
nephish at xit.net
Sun Jul 3 05:41:09 CEST 2005
i have a file that i want to read.
each line in the file is the name of a file.
the next line is how many lines are in that file.
example of loglist.txt
so log1 is a text file that has 232 lines in it.
ok, so what i want to do is read this file, see if the file i am looking
for is in it
and if so, i need to know how many lines are in the file.
here is what i have so far.
#get a list of Logs in logs folder
LogFiles = os.listdir('/home/nephish/Projects/Piv_GCI/logs')
#open the loglist file and read the lines
LogList = open('home/nephish/Projects/Piv/logs/LogList.txt', 'r')
LogsRead = LogList.readlines()
#see if there is a new log file.
for i in LogFiles:
if LogFiles[i] not in LogList:
#if there is a new log, open it and read the lines
NewLog = open('/home/nephish/Projects/Piv_CGI/logs'+StrName,'r')
#print the lines (testing only)
for x in NewLogRead:
print '\n' #end for loop
else: #if the log file is not new,
um this is where i am stuck. i need search the LogList for the name of
the name of the file in LogFiles and get the line number back so i can
use it to compare with how many lines are in the log file so i can only
process the data in the new lines ... does this make sense ?
i need to find the item in a list, and when found, return the next line.
More information about the Tutor