from glob import iglob
时间: 2023-09-21 09:07:02 浏览: 87
`iglob` is a function provided by the `glob` module in Python. It allows you to search for files with a specified pattern using wildcard characters. The `iglob` function returns an iterator that yields file paths matching the given pattern.
Here's an example usage of `iglob`:
```python
from glob import iglob
# Search for all text files in the current directory and its subdirectories
for file_path in iglob('**/*.txt', recursive=True):
print(file_path)
```
In the above code, `**/*.txt` is the file pattern we are searching for. The `**` matches zero or more subdirectories, and `*.txt` matches any file ending with `.txt`. By setting `recursive=True`, `iglob` will search in all subdirectories as well.
Note that `iglob` returns an iterator, so you can loop through the results directly without loading all file paths into memory at once.
阅读全文