def lines_generator(base_folder, exclude=None):
    for dirpath, dirs, files in os.walk(base_folder):
        for filename in files:
            if filename.endswith('.txt'):
                fullPath = os.path.join(dirpath, filename)
with open(fullPath) as f:
    for line in f:
        cleanLine = line.strip()
if exclude is None or cleanLine not in exclude:
    yield cleanLine
Python random lines from subfolders