1 2 3 4 5 6 7 8 9 10 11
from functools import partial def list_files(): for fn in ["example.txt", "data.txt"]: def func(fn): return "sample contents of %s" % fn yield fn, partial(func, fn) for fn, body in list(list_files()): if fn.endswith('.txt'): print body()
1 2
sample contents of example.txt sample contents of data.txt