"Sean Carolan" <scaro...@gmail.com> wrote

> The first two lines are redundant you only need the last one.

I should have clarified, the "if line.startswith" part was used to
break out of the previous for loop, which was used to import the
other, shorter strings.

Thats fair enough if you are doing something with those shorter strings. But if not the whole loop is redundant, you only need the split. Your original post did not mention any processing of the earlier lines.

But even if you were you could still use the split() first then process the first element in a loop and assign the second element to your variable:

stuff, store = theFile.read().split('notes\n')
for line in stuff.split():
  # process thing

That way there is no need for a break test.

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