I have a file with a bunch of information. For example, all of the lines follow the same pattern as this:
Nebraska
You could use a regular expression:
import re regexp = re.compile('(.*?)<\/school>') with open('Pro.txt') as fo: for rec in fo: match = regexp.match(rec) if match: text = match.groups()[0] print(text)