Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93041

Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

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 <python-python-list@m.gmane.org>
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 <tjreedy@udel.edu>
Subject Re: Simplest/Idiomatic way to count files in a directory (using pathlib)
Date Tue, 23 Jun 2015 12:17:34 -0400
References <mailman.712.1435012328.13271.python-list@python.org> <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.731.1435076289.13271.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 6/22/2015 9:32 PM, Paul Rubin wrote:
> Travis Griggs <travisgriggs@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Simplest/Idiomatic way to count files in a directory (using pathlib) Travis Griggs <travisgriggs@gmail.com> - 2015-06-22 15:31 -0700
  Re: Simplest/Idiomatic way to count files in a directory (using pathlib) Paul Rubin <no.email@nospam.invalid> - 2015-06-22 18:32 -0700
    Re: Simplest/Idiomatic way to count files in a directory (using pathlib) Terry Reedy <tjreedy@udel.edu> - 2015-06-23 12:17 -0400

csiph-web