[Tutor] Reading only a few specific lines of a file
Jason Conner
jasonbconner at gmail.com
Sun May 25 01:09:13 CEST 2008
Hey guys,
I went with a combination of the above, though I tried several different
solutions. Here's what I ended up with:
def loadItem(self, objectToLoad):
wordList = []
fobj = open('/home/jason.conner/Documents/Python/objectconfig.txt', 'r')
for line in fobj:
if line == objectToLoad:
wordList.append(line)
for i in range(5):
wordList.append(fobj.next())
Though it did take me a few minutes to figure out that I needed to include
the \n in the objectToLoad variable to get it to work in its present form,
it works great. Thanks for all your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080525/f0941161/attachment.htm>
More information about the Tutor
mailing list