Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: Duplicate Output Date: Wed, 27 Jan 2016 10:19:59 +0100 Organization: None Lines: 18 Message-ID: References: <56A7BF9A.1070709@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de cQxtOqKRSUxYYHuW7v1mggAbqE3AW1t2lO/jvKFHcnPA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python3': 0.05; 'filenames': 0.07; 'exception:': 0.09; 'mkdir': 0.09; 'os;': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'chmod': 0.16; 'inaccessible': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'sudo': 0.16; 'wrote:': 0.16; '"",': 0.22; '(most': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'traceback': 0.33; 'file': 0.34; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'skip:n 10': 0.62; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8704.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102148 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 "", line 1, in StopIteration