Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread Alan Gauld
"Alan Gauld" <[EMAIL PROTECTED]> wrote > found2 = False > for line in file("prueba.txt"): > if '2' in line: found2 = True > if found2: print line > else: continue Just after posting I realised it would be better to do: found2 = False for line in file("prueba.txt"): found2 = foun

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread Alan Gauld
"jon vs. python" <[EMAIL PROTECTED]> wrote in > I wanted a little script that would print the line containing "2" > and every > line containing "1" after it. I've tried this: > def p(): >f = file("prueba.txt",'r') >for startline in f.read(): >if startline.find("2") != -1: >

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread Kent Johnson
jon vs. python wrote: > Hi everyone, > I have a file with this content: > > "1 > 1 > 1 > 1 > 1 > 1 > 1 > 2 > 1 > 1" > > I wanted a little script that would print the line containing "2" and > every line containing "1" after it. I've tried this: > > >>> def p(): > f = file("prueba.txt",'r')

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread bob gailer
Luis N wrote: > On Dec 16, 2007 10:17 PM, jon vs. python <[EMAIL PROTECTED]> wrote: > >> Hi everyone, >> I have a file with this content: >> >> "1 >> 1 >> 1 >> 1 >> 1 >> 1 >> 1 >> 2 >> 1 >> 1" >> >> I wanted a little script that would print the line containing "2" and every >> line containing "1

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread Bob Gailer
[snip] now ponder this: f=file("prueba.txt.log") for startline in f: if startline.find("2") != -1: for endline in f: print endline # etc. ___ Tutor maillist - Tutor@python.org htt

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread Luis N
On Dec 16, 2007 10:17 PM, jon vs. python <[EMAIL PROTECTED]> wrote: > Hi everyone, > I have a file with this content: > > "1 > 1 > 1 > 1 > 1 > 1 > 1 > 2 > 1 > 1" > > I wanted a little script that would print the line containing "2" and every > line containing "1" after it. I've tried this: > > >>>

Re: [Tutor] Nested, line by line, file reading

2007-12-16 Thread bob gailer
jon vs. python wrote: > Hi everyone, > I have a file with this content: > > "1 > 1 > 1 > 1 > 1 > 1 > 1 > 2 > 1 > 1" > > I wanted a little script that would print the line containing "2" and > every line containing "1" after it. I've tried this: > > >>> def p(): > f = file("prueba.txt",'r') >

[Tutor] Nested, line by line, file reading

2007-12-16 Thread jon vs. python
Hi everyone, I have a file with this content: "1 1 1 1 1 1 1 2 1 1" I wanted a little script that would print the line containing "2" and every line containing "1" after it. I've tried this: >>> def p(): f = file("prueba.txt",'r') for startline in f.read(): if startline.find("2")