Feb-08-2018, 05:34 PM
You can also make a generator, which is cool :p
If your jobs file is massive, and you could potentially have millions of matches, this is something similar to what you'd want to be using.
If your jobs file is massive, and you could potentially have millions of matches, this is something similar to what you'd want to be using.
def find_within(haystack, match, processor=None): with open(haystack) as file: for line in file: if processor: line = processor(line) if match(line): yield line matches = find_within("jobs.txt", lambda job: job[0] == jobname, lambda line: line.split("|")) for match in matches: print(match[0], match[1])