"Bala subramanian" <bala.biophys...@gmail.com> wrote

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.startswith() returns a boolean result - True or False
Neither of these is in your list so the if test always passes.

You need to apply startwith to each item in your list.
You could use a list comprehension/generator expression
- or find another approach, maybe using slicing?

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to