def ChargeExtractor(filename): with open(filename) as gaussfile: charge_section = False for line in gaussfile: if charge_section: print(line.split()) if "Mulliken atomic charges" in line: charge_section = True if "Sum of Mulliken atomic charges" in line: break ChargeExtractor("NSC_1317.log")