问题
Consider this folder containing two files:
test/
foo
.bar
Calling glob.glob('*') on this folder won't list the hidden .bar
file:
>>> glob.glob('test/*')
['test/foo']
But pathlib.Path.glob('*') will:
>>> list(Path('test').glob('*'))
[PosixPath('test/.bar'), PosixPath('test/foo')]
I'd like to know if this is intended or possibly a bug/oversight.
The glob module documentation states that files starting with a dot are special cased:
glob treats filenames beginning with a dot (.) as special cases
Meaning that the result given by glob.glob('*')
is intended. But what about pathlib's glob
? I couldn't find any relevant information in the docs. Is this the intended behavior? Shouldn't both functions produce the same results?
回答1:
As per issue #26096 on the official bug tracker, this difference has been deemed not a bug
and is therefore completely intended.
Credits to @vaultah for the find.
来源:https://stackoverflow.com/questions/49862648/why-do-glob-glob-and-pathlib-path-glob-treat-hidden-files-differently