Implicit iteration is replaced by the iterdir() method

This commit is contained in:
Antoine Pitrou 2013-11-16 20:08:09 +01:00
parent 4e925eb9ad
commit 0866846d15
1 changed files with 4 additions and 3 deletions

View File

@ -589,10 +589,11 @@ the way. It is the only operation which will remove "``..``" path components.
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 @@ Simple (non-recursive) directory access is done by iteration::
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::