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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.121 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.76; '*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; 'all.': 0.24; 'subject:/': 0.29; '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; 'received:172.16': 0.38; 'say': 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=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=0NNfcGH+soA1o9D1yAtpKhTZ7F9GYJIqR3OAc8sPJaQ=; b=Xkat4CnAvcQdIUk9PmeQxnWxXH2cDKiESCC4gALEOu9dUFrsJrskOxTh5rgAJeYL63 vQ0FSoizcKkPvMhHWJcJLUoG1dWUfn3mdbLieLq61lEDv2GkNk+DwhOXNEnzUZwu4Tje pPgwimcaU3tVxcQvbxxfXdp4iav2bCigzGYcALX8wki+H62Y20cHLS9rLdr0cDqUIt4B Umy+dkrloNToulSfCt3Fy/uW2BcPDqJHfesMM+SAujDN6VBxViW2nEXXOjneJtOf3Yh6 5qbS7NwWXxXGx0DWTzT2lb122njZN+yaxFew6DmOp0znwH0lHFSWxlvlsYOEIucG4ME8 o/4Q== X-Received: by 10.70.101.168 with SMTP id fh8mr62538111pdb.15.1435012319964; Mon, 22 Jun 2015 15:31:59 -0700 (PDT) From: Travis Griggs Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Simplest/Idiomatic way to count files in a directory (using pathlib) Date: Mon, 22 Jun 2015 15:31:58 -0700 To: Python Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435012328 news.xs4all.nl 2847 [2001:888:2000:d::a6]:34164 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93019 Subject nearly says it all. If i=E2=80=99m using pathlib, what=E2=80=99s 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()) I don=E2=80=99t say anything on the in the .stat() object that helps me. I could of course do the 4 liner: count =3D 0 for _ in self.path.iterdir(): count +=3D 1 return count The following seems to obtuse/clever for its own good: return sum(1 for _ in self.path.iterdir())=