Re: [Tutor] Reading only a few specific lines of a file

2008-05-25 Thread Chester
I don't know then. Just hack your way through and tell us how did you manage to do it. ;) On Sun, May 25, 2008 at 9:32 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > Forwarding to the list with my reply... > > On Sun, May 25, 2008 at 2:20 PM, Chester <[EMAIL PROTECTED]> wrote: > > Python uses \n

Re: [Tutor] Reading only a few specific lines of a file

2008-05-25 Thread Kent Johnson
Forwarding to the list with my reply... On Sun, May 25, 2008 at 2:20 PM, Chester <[EMAIL PROTECTED]> wrote: > Python uses \n as the newline character (which is a UNIX/Linux newline > character). I see you have Python for Windows installed and running it on > the Windows OS. The file objectconfig

Re: [Tutor] Reading only a few specific lines of a file

2008-05-25 Thread Kent Johnson
On Sat, May 24, 2008 at 7:09 PM, Jason Conner <[EMAIL PROTECTED]> wrote: > def loadItem(self, objectToLoad): > wordList = [] > fobj = open('/home/jason.conner/Documents/Python/objectconfig.txt', 'r') > > for line in fobj: > if line == objectToLoad: > wordList.append

Re: [Tutor] Reading only a few specific lines of a file

2008-05-24 Thread Jason Conner
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 == obj

Re: [Tutor] Reading only a few specific lines of a file

2008-05-23 Thread Alan Gauld
"Marilyn Davis" <[EMAIL PROTECTED]> wrote (I'm sorry for the duplicate, Alan.) I didn't see a duplicate! ;-) linecount = 0 for line in file("itemconfig.txt", 'rU'): if line == objectToLoad or linecount > 0: if linecount == 0: linecount = 5 itemList.append(line.split()[:5

Re: [Tutor] Reading only a few specific lines of a file

2008-05-23 Thread Marilyn Davis
(I'm sorry for the duplicate, Alan.) On Fri, May 23, 2008 3:49 am, Alan Gauld wrote: > "Jason Conner" <[EMAIL PROTECTED]> wrote > > >> 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

Re: [Tutor] Reading only a few specific lines of a file

2008-05-23 Thread Alan Gauld
"Jason Conner" <[EMAIL PROTECTED]> wrote 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):

Re: [Tutor] Reading only a few specific lines of a file

2008-05-22 Thread John Fouhy
On 23/05/2008, Jason Conner <[EMAIL PROTECTED]> wrote: Hi Jason, > def loadItem(self, objectToLoad): > x = 0 > wordList = [] > fobj = file() > fobj.open("itemconfig.txt", 'rU') > > for line in fobj.readline(): In recent pythons, you can write this better as: for line in fob

[Tutor] Reading only a few specific lines of a file

2008-05-22 Thread Jason Conner
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: