You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Undocumented functions glob0() and glob1() were just helpers for glob.iglob(). They are not underscored because the glob module has __all__. They survived numerous refactorings only because they were used in the msilib module and some MSI related scripts. But the msilib module and these scripts have been removed.
glob1(root_dir, pattern) is equivalent to iglob1(os.path.join(glob.escape(root_dir), pattern)), but more restricted and slightly faster, because it does not need to escape root_dir and process the result.
Other alternative is iglob(pattern, root_dir=root_dir), which can even be faster, but it emits paths relative to root_dir. You can use (os.path.join(root_dir, p) for p in iglob(pattern, root_dir=root_dir)) if you need to append root_dir. Actually, creating an efficient replacement of glob1() was one of purposes of root_dir.
glob0(root_dir, name) just checks that os.path.join(root_dir, name) exists. I did not see its use in third-party code.
Two small corrections: the functions return results that are relative to dirname (i.e. they don't include dirname as a prefix), and the return value is a list (so they're more similar to glob() than iglob()).
Activity
barneygale commentedon Mar 29, 2024
Two small corrections: the functions return results that are relative to dirname (i.e. they don't include dirname as a prefix), and the return value is a list (so they're more similar to
glob()thaniglob()).Both functions can be approximated by
glob.glob(pattern, root_dir=dirname)I believe, without the need to escape or join dirname.pythonGH-117337: Deprecated `glob.glob0()` and `glob.glob1()`.
Merge branch 'main' into pythongh-117337-deprecate-glob0-glob1
GH-117337: Deprecate `glob.glob0()` and `glob.glob1()`. (#117371)
Squashed commit of the following:
Squashed commit of the following:
pythonGH-117337: Deprecate `glob.glob0()` and `glob.glob1()`. (python…