I am trying to parse certain paragraphs out of a text file. The paragraph I am trying to parse is labeled as so:
ABST
PAL An abrasion-resistant laminate is prepared by providing an ultra thin
coating of mineral particles and micro crystalline cellulose on the
surface of conventional printed paper, followed by impregnating the paper
with a conventional laminating resin, and then using the print paper so
obtained in a laminating process without the necessity of using an overlay
sheet.
PARN
So far all I have gotten is:
with open('file.txt', 'r+') as f:
for line in f:
if line.startswith("ABST"):
print f.next()
This is only leaving me with the first line of the paragraph. What I would like to is something along the lines of:
with open('file.txt', 'r+') as f:
for line in f:
if line.startswith("ABST"):
*print lines until next header*
I realize this is not too complicated but I have been stuck in a rut so any suggestion will help.
Should do the trick… Straight and to the point. In any case, you can let the loop handle the iteration for you, just make sure you remember if you should print or not.