glob.glob() vs glob.iglob()
glob.glob() and glob.iglob() are both Python Glob Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. glob.glob(): Returns a list of file paths matching a pathname pattern. Its syntax is glob.glob(pathname, *, root_dir=None, dir_fd=None, recursive=False), and it returns list of path strings glob.iglob(): Like glob() but returns an iterator instead of a list (memory efficient). Its syntax is glob.iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False), and it returns iterator of path strings Example of glob.glob(): import glob
glob.glob("*.py") # ["script.py", "utils.py"]
glob.glob("**/*.py", recursive=True) # All .py recursively. Example of glob.iglob(): for f in glob.iglob("data/*.csv"):
process(f). Read the full references for glob.glob() and glob.iglob() to see parameters, edge cases, and example code side by side. Both belong to the Glob Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.