Well,
I was somewhat confused with all of the answers so I decided to go with
my/following method. Kent's method has 4 fewer lines of code than mine and
cleaner. Please correct me if I am fundamentally wrong.
f=open('file.txt',r)
for line in f.read().split():
if line == "3"
position = True
else:
position = False
if position == True
print line
position = False
f.close()
On Fri, May 2, 2008 at 6:55 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> On Fri, May 2, 2008 at 3:55 AM, Roel Schroeven
> <[EMAIL PROTECTED]> wrote:
>
> > Shouldn't it even be 'line = f.next()'?
>
> Wow, I think Brain Stormer should get a prize. I'm not sure what the
> prize is, but his short program has elicited incomplete and inaccurate
> answers from three of the top posters to this list! I *think* this is
> a complete answer:
>
> f = open('file.txt',r)
> for line in f:
> if line.rstrip() == "3":
> line = f.next()
> print line
> break # put this in if there is only one line you want to print
> f.close()
>
> ...awaiting any further corrections :-)
> Kent
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor