Hey guys,
Very new to programming Python, and I'm running up against a problem. I am
building a program that will take a text file, search for a string in that
text file. Once it finds the string its looking for, I want to put the next
five lines of text into a variable. Here's what I have so far:
def loadItem(self, objectToLoad):
x = 0
wordList = []
fobj = file()
fobj.open("itemconfig.txt", 'rU')
for line in fobj.readline():
if line == objectToLoad:
while x != 5
for word in line.split():
wordList.append(word)
x += 1
thing = item(wordList[0], wordList[1], wordList[2], wordList[3],
wordList[4])
itemList.append(thing)
This, however, highlights my problem.
"if line == objectToLoad:"
ceases to be true on the second iteration, as it reads in another line. Is
there a better way to do this, or should I just parse the whole document,
and look for the strings I want to find?
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor