Peter Otten wrote: > or use next(): > > filenames = next(walk("."))[2] > print(filenames)
Be warned though that if you try this with a non-existent or otherwise inaccessible directory you will get an exception: $ sudo mkdir forbidden $ sudo chmod a-r forbidden $ python3 -c 'import os; next(os.walk("forbidden"))' Traceback (most recent call last): File "<string>", line 1, in <module> StopIteration -- https://mail.python.org/mailman/listinfo/python-list