[Tutor] searching for multiple strings in line.starswith()

Joel Goldstick joel.goldstick at gmail.com
Mon Jul 19 20:32:49 CEST 2010


On Mon, Jul 19, 2010 at 2:07 PM, Luke Paireepinart
<rabidpoobear at gmail.com>wrote:

> You are using Line.startswith incorrectly, read the docs on it and see if
> you can figure out your problem an key us know. Pay attention to the
> parameters it takes and the values it returns.
>
> Sent from my iPhone
>
> On Jul 19, 2010, at 11:18 AM, Bala subramanian <bala.biophysics at gmail.com>
> wrote:
>
> > Friends,
> > I have to extract the line from a file that does not contain a set of
> strings in the start of the line, i wrote the following code.
> >
> > for index, line in enumerate(myvar.split('\n')):
> >     if line.startswith('') not in ['#Cluster','#Centroid','#End']:
> >         line=line.split()
> >         print line
> >
> > The code works without error but it seems that the condition is not
> applied. What is the correct way of searching for multiple strings at the
> start of a line.
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

I recently used this code:

split_line = line.split(' ', 1)

which takes the text from the start up to the first space.

then something like:

if split_line not in [...etc....]
    print split_line
    # or if you want the original line print line





-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100719/5f06d0ac/attachment-0001.html>


More information about the Tutor mailing list