_glob.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:SDK 作者: Keypirinha 项目源码 文件源码
def iglob(*args, include_hidden=False, **kwargs):
    """
    A :py:func:`glob.iglob` that **optionally** but **truly** excludes hidden
    files (i.e. even on *Windows*).

    :py:func:`glob._ishidden`, which is implicitly used by :py:func:`glob.glob`
    and :py:func:`glob.iglob` always filters out *dot* files but does not mind
    about file's *HIDDEN* attribute on Windows.

    **CAUTION:** this function **is not** thread-safe as it installs a trap at
    runtime (i.e. for :py:func:`glob._ishidden`). The ``glob`` module must not
    be used concurrently to this function.
    """
    orig_ishidden = _glob._ishidden
    if include_hidden:
        _glob._ishidden = lambda x: False
    else:
        # original glob._ishidden() only removes "dot" files
        # on windows, files have a "hidden" attribute
        _glob._ishidden = _ishidden
    try:
        yield from _glob.iglob(*args, **kwargs)
    finally:
        _glob._ishidden = orig_ishidden
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号