all Python 3globfunction
glob.iglob()
file search
The same as glob.glob() but returns an iterator that yields paths one by one instead of building a list.
Syntax
glob.iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False, include_hidden=False)
It saves memory on large trees, but the iterator is single-use: a second pass yields nothing. Files created or removed during the walk may or may not appear. An iterator has no len(); to count, use a list or sum(1 for _ in ...).
Examples
import glob
for name in ['a.log', 'b.log']:
open(name, 'w').close()
it = glob.iglob('*.log')
print(sorted(it)) # → ['a.log', 'b.log']
print(list(it)) # → [] — итератор уже исчерпан
See also
Open in the full glossarydocs.python.orgReport an inaccuracy