Implicit iteration is replaced by the iterdir() method
This commit is contained in:
parent
4e925eb9ad
commit
0866846d15
|
@ -589,10 +589,11 @@ the way. It is the only operation which will remove "``..``" path components.
|
||||||
Directory walking
|
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')
|
>>> p = Path('docs')
|
||||||
>>> for child in p: child
|
>>> for child in p.iterdir(): child
|
||||||
...
|
...
|
||||||
PosixPath('docs/conf.py')
|
PosixPath('docs/conf.py')
|
||||||
PosixPath('docs/_templates')
|
PosixPath('docs/_templates')
|
||||||
|
@ -605,7 +606,7 @@ Simple (non-recursive) directory access is done by iteration::
|
||||||
This allows simple filtering through list comprehensions::
|
This allows simple filtering through list comprehensions::
|
||||||
|
|
||||||
>>> p = Path('.')
|
>>> 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')]
|
[PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'), PosixPath('__pycache__'), PosixPath('build')]
|
||||||
|
|
||||||
Simple and recursive globbing is also provided::
|
Simple and recursive globbing is also provided::
|
||||||
|
|
Loading…
Reference in New Issue