考虑此文件夹包含两个文件:
Consider this folder containing two files:
test/ foo .bar在此文件夹上调用 glob.glob('*') 不会列出隐藏的.bar文件:
Calling glob.glob('*') on this folder won't list the hidden .bar file:
>>> glob.glob('test/*') ['test/foo']但是 pathlib.Path.glob('*') 将:
>>> list(Path('test').glob('*')) [PosixPath('test/.bar'), PosixPath('test/foo')]我想知道这是故意的还是可能的错误/疏忽.
I'd like to know if this is intended or possibly a bug/oversight.
glob模块文档指出以点开头的文件是特殊情况:
The glob module documentation states that files starting with a dot are special cased:
glob将以点(.)开头的文件名视为特殊情况
glob treats filenames beginning with a dot (.) as special cases
表示要使用glob.glob('*')给出的结果.但是pathlib的glob呢?我在文档中找不到任何相关信息.这是预期的行为吗?两种功能都不应该产生相同的结果吗?
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?
推荐答案根据 issue#26096 官方的错误跟踪器,这种区别被认为是not a bug,因此完全有意.
As per issue #26096 on the official bug tracker, this difference has been deemed not a bug and is therefore completely intended.
为查找找到 @vaultah .
更多推荐
为什么glob.glob和pathlib.Path.glob对隐藏文件的处理方式不同?
发布评论