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

编程入门 行业动态 更新时间:2024-10-24 18:17:45
本文介绍了为什么glob.glob和pathlib.Path.glob对隐藏文件的处理方式不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑此文件夹包含两个文件:

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对隐藏文件的处理方式不同?

本文发布于:2023-10-07 14:36:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:隐藏文件   方式   glob   pathlib   Path

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!