[Python-checkins] peps: Implicit iteration is replaced by the iterdir() method

antoine.pitrou python-checkins at python.org
Sat Nov 16 20:08:13 CET 2013


http://hg.python.org/peps/rev/d7a201b5c9fc
changeset:   5280:d7a201b5c9fc
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sat Nov 16 20:08:09 2013 +0100
summary:
  Implicit iteration is replaced by the iterdir() method

files:
  pep-0428.txt |  7 ++++---
  1 files changed, 4 insertions(+), 3 deletions(-)


diff --git a/pep-0428.txt b/pep-0428.txt
--- a/pep-0428.txt
+++ b/pep-0428.txt
@@ -589,10 +589,11 @@
 Directory walking
 -----------------
 
-Simple (non-recursive) directory access is done by iteration::
+Simple (non-recursive) directory access is done by calling the iterdir()
+method, which returns an iterator over the child paths::
 
     >>> p = Path('docs')
-    >>> for child in p: child
+    >>> for child in p.iterdir(): child
     ...
     PosixPath('docs/conf.py')
     PosixPath('docs/_templates')
@@ -605,7 +606,7 @@
 This allows simple filtering through list comprehensions::
 
     >>> p = Path('.')
-    >>> [child for child in p if child.is_dir()]
+    >>> [child for child in p.iterdir() if child.is_dir()]
     [PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'), PosixPath('__pycache__'), PosixPath('build')]
 
 Simple and recursive globbing is also provided::

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list