On Thu, May 1, 2008 at 5:04 PM, Brain Stormer <[EMAIL PROTECTED]> wrote:
> I have the following code:
>
> f = open('file.txt',r)
> for line in f.read():
>      if line == "3":
>            line.next

Try
  f.next()

line is a string, it doesn't have a next() method. The file itself is
iterable and has next(). Don't forget the parentheses!

Kent

>            print line
> f.close()
>
> The file.txt looks like
> 1
>  2
> 3
> 4
> 5
>
> I would like the code to output "4"
>
> but I don't know how to use the next.  Are there any other way?
>
> Thanks
>
>
>
>
> _______________________________________________
>  Tutor maillist  -  [email protected]
>  http://mail.python.org/mailman/listinfo/tutor
>
>
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to