# gencat.py # # Concatenate multiple generators into a single sequence def gen_cat(sources): for s in sources: for item in s: yield item # Example use if __name__ == '__main__': from genfind import gen_find from genopen import gen_open lognames = gen_find("access-log*", "www") logfiles = gen_open(lognames) loglines = gen_cat(logfiles) for line in loglines: print(line)
def lines_from_dir(filepat, dirname): names = gen_find(filepat,dirname) files = gen_open(names) lines = gen_cat(files) return lines
# gencat.py # # Concatenate multiple generators into a single sequence def gen_cat(sources): for s in sources: for item in s: yield item # Example use if __name__ == '__main__': from genfind import gen_find from genopen import gen_open lognames = gen_find("access-log*","www") logfiles = gen_open(lognames) loglines = gen_cat(logfiles) for line in loglines: print line,
def lines_from_dir(filepat, dirname): names = Path(dirname).rglob(filepat) files = gen_open(names) lines = gen_cat(files) return lines