简体   繁体   English

为什么glob.glob和pathlib.Path.glob以不同方式处理隐藏文件?

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

Consider this folder containing two files: 考虑包含两个文件的文件夹:

test/
    foo
    .bar

Calling glob.glob('*') on this folder won't list the hidden .bar file: 在此文件夹上调用glob.glob('*')将不会列出隐藏的.bar文件:

>>> glob.glob('test/*')
['test/foo']

But pathlib.Path.glob('*') will: 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. 我想知道这是有意还是可能是错误/疏忽。


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将以点(。)开头的文件名视为特殊情况

Meaning that the result given by glob.glob('*') is intended. 这意味着glob.glob('*')给出的结果是有意的。 But what about pathlib's glob ? 但是pathlib的glob怎么样? I couldn't find any relevant information in the docs. 我在文档中找不到任何相关信息。 Is this the intended behavior? 这是预期的行为吗? Shouldn't both functions produce the same results? 两个函数不应该产生相同的结果吗?

As per issue #26096 on the official bug tracker, this difference has been deemed not a bug and is therefore completely intended. 根据官方错误跟踪器上的问题#26096 ,这种差异被认为not a bug ,因此完全是有意的。

Credits to @vaultah for the find. 归功于@vaultah的发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM