複雑なジェネレーターを記述する際には、yield from命令を利用することで処理を分離でき、コードがより見通しやすくなる。
gen_from.py
def read_files(*files):
for file in files:
yield from read_lines(file)
def read_lines(path):
with open(path,'r',encoding='UTF-8') as file:
for line in file:
yield line.rstrip('\n')
for line in read_files("./path/1","./path/2","./path/3"):
print(line)
独習Pthon 9.2.4 より引用