the usage of 'yield' keyword

Tim Golden mail at
Wed Oct 14 13:36:42 CEST 2009

Dave Angel wrote:

> def find(root):
>    for pdf in os.walk(root, topdown=False):
>            for file in pdf[2]:
>                yield os.path.join(pdf[0],file)

At the risk of nitpicking, I think that a modicum of
tuple-unpacking would aid readability here:


for dirpath, dirnames, filenames in os.walk (root, topdown=False):
  for filename in filenames:
    yield os.path.join (dirpath, filename)



More information about the Python-list mailing list