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)

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Simplest/Idiomatic way to count files in a directory (using pathlib)
Date 2015-06-23 12:17 -0400
References <mailman.712.1435012328.13271.python-list@python.org> <87k2uvjjjv.fsf@nightsong.com>
Newsgroups comp.lang.python
Message-ID <mailman.731.1435076289.13271.python-list@python.org> (permalink)

Show all headers | 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