"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
"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:
>
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')
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
[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
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:
>
> >>>
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')
>
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")