Duplicate Output

Peter Otten __peter__ at web.de
Wed Jan 27 04:19:59 EST 2016


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





More information about the Python-list mailing list