Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93020
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <travisgriggs@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.107 |
| X-Spam-Level | * |
| X-Spam-Evidence | '*H*': 0.79; '*S*': 0.00; 'subject:files': 0.09; 'subject:using': 0.09; '(at': 0.13; 'first)': 0.16; 'i\xe2\x80\x99m': 0.16; 'nearly': 0.23; 'seems': 0.24; 'header:In- Reply-To:1': 0.24; 'all.': 0.24; 'subject:/': 0.29; 'work.': 0.30; 'says': 0.32; 'surprised': 0.33; 'received:google.com': 0.34; 'message-id:@gmail.com': 0.35; 'could': 0.35; 'to:addr:python- list': 0.35; 'subject:: ': 0.37; 'received:172.16': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'subject: (': 0.40; 'helps': 0.61; 'header:Message-Id:1': 0.62; 'course': 0.64; 'subject': 0.68; 'good:': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=lOz7sR/c8NYHsJLuD4sYrg0sQzC8+/mxkYtTUqnSlnE=; b=EjzPTa3c2dRo2jPoDZqmgjHBR2N1Atitxi13+eeUNz61m6ClWuqjerByLAtnve11hc NAH5viyt4TNbhx53dMg9xQuZhk6goX/7SwoFB5C8BprWgncwsM+2gjFIQpf58z4h5XiL Dqe30IFiyukKeQ/sT/RLPfCpdoxTvSnhCRUFD3iRmbElKoWAxLK/jQkRP/yWqAD0tLEE R0ajFiJSB0WQjcxT51ZIN5QyrP5yaeATWLBV/nn9/SoZqN4LaOY0jgHc2UsbCyj1inot JJYgHa4BqEYtPUHTox1AcYpTYA63XFeL39lQIYiafTbnhlXbpJcKyXu6eVHgU+2Ylkak Uj2w== |
| X-Received | by 10.70.118.73 with SMTP id kk9mr63742831pdb.150.1435012399325; Mon, 22 Jun 2015 15:33:19 -0700 (PDT) |
| Content-Type | text/plain; charset=utf-8 |
| Mime-Version | 1.0 (Mac OS X Mail 8.2 \(2098\)) |
| Subject | Re: Simplest/Idiomatic way to count files in a directory (using pathlib) |
| From | Travis Griggs <travisgriggs@gmail.com> |
| In-Reply-To | <8B8C6022-75BE-41FC-9B18-7D89AD34A35A@gmail.com> |
| Date | Mon, 22 Jun 2015 15:33:18 -0700 |
| Content-Transfer-Encoding | quoted-printable |
| References | <8B8C6022-75BE-41FC-9B18-7D89AD34A35A@gmail.com> |
| To | Python <python-list@python.org> |
| X-Mailer | Apple Mail (2.2098) |
| 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.713.1435012407.13271.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1435012407 news.xs4all.nl 2865 [2001:888:2000:d::a6]:35768 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:93020 |
Show key headers only | View raw
<I should proof my posts before I send them, sorry>
Subject nearly says it all.
If i’m using pathlib, what’s the simplest/idiomatic way to simply count how many files are in a given directory?
I was surprised (at first) when
len(self.path.iterdir())
didn’t work.
I don’t see anything in the .stat() object that helps me.
I could of course do the 4 liner:
count = 0
for _ in self.path.iterdir():
count += 1
return count
The following seems to obtuse/clever for its own good:
return sum(1 for _ in self.path.iterdir())
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Simplest/Idiomatic way to count files in a directory (using pathlib) Travis Griggs <travisgriggs@gmail.com> - 2015-06-22 15:33 -0700
csiph-web