def filter_file(fn): print("Scanning %s..." % fn) locations = find_nhs_numbers(fn) if locations is None: print("Failed to open.") return False nhs_numbers = [] try: f = open("DEP2.CSV", 'rb') except IOError: return for location in locations: f.seek(location) nhs_numbers.append(f.read(10)) f.close() print("found %d valid NHS numbers" % len(locations)) replace_nhs_numbers(fn, locations)