f=open('file.txt',r)
position =False
for line in f.read().split():
   if position == True
         print line
         position = False
   if line == "3":
         position = True
   else:
         position = False
f.close()



On Fri, May 2, 2008 at 10:28 AM, Brain Stormer <[EMAIL PROTECTED]> wrote:

> You are correct.  It is missing the ":" and it will print "3"
>
> On Fri, May 2, 2008 at 10:18 AM, bob gailer <[EMAIL PROTECTED]> wrote:
>
> > Brain Stormer wrote:
> >
> > > 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()
> > >
> > >  Yikes! That won't compile (missing : at end of if statements). After
> > correcting, will print 3.
> >
> > How about this if you want less lines of code:
> >
> > f = open('file.txt',r).readlines()
> > print f[[x+1 for x,line in enumerate(f) if line.rstrip() == "3"][0]]
> >
> >
> > --
> > Bob Gailer
> > 919-636-4239 Chapel Hill, NC
> >
> >
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to