Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'python,': 0.02; 'counting': 0.07; 'finite': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:files': 0.09; 'subject:using': 0.09; 'jan': 0.11; 'callables': 0.16; 'itertools': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'statement.': 0.16; 'subject: \n ': 0.16; 'travis': 0.16; 'wrote:': 0.16; 'suppose': 0.22; "i've": 0.24; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'define': 0.27; 'subject:/': 0.29; 'terry': 0.29; 'that.': 0.30; 'generally': 0.32; 'could': 0.35; 'to:addr:python-list': 0.35; 'done': 0.35; 'something': 0.35; 'subject:: ': 0.37; 'version': 0.38; 'received:org': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'subject: (': 0.40; 'direct': 0.70; 'obvious': 0.72; 'good:': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Simplest/Idiomatic way to count files in a directory (using pathlib) Date: Tue, 23 Jun 2015 12:17:34 -0400 References: <87k2uvjjjv.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 In-Reply-To: <87k2uvjjjv.fsf@nightsong.com> 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: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435076289 news.xs4all.nl 2927 [2001:888:2000:d::a6]:50409 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93041 On 6/22/2015 9:32 PM, Paul Rubin wrote: > Travis Griggs writes: >> The following seems to obtuse/clever for its own good: >> return sum(1 for _ in self.path.iterdir()) I disagree. For one who understands counting and Python, this is a direct way to define the count of a finite iterable. A functionalist would prefer it to the obvious 3-line version with a for statement. > I've generally done something like that. I suppose it could be added to > itertools. itertools callables all produce iterators. The above only consumes an iterable. -- Terry Jan Reedy