Why do glob.glob and pathlib.Path.glob treat hidden files differently?

那年仲夏 提交于 2020-01-24 02:20:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!