使用 os.scandir() 在 pycharm 中导致“未解析的属性引用”警告

问题描述

我在 pycharm 中有以下 python 代码:

# search for files or folders with two or more adjacent spaces
def twoplusspaces(path):

    srchr = os.scandir(path) # get our iterator

    # iterate through folders and files looking for adjacent blank spaces
    for entry in srchr:
        if "  " in entry.name:
            print(entry.name) # print name of file/folder with 2+ spaces
        if entry.is_dir():
            twoplusspaces(path + "\\" + entry.name) # recursive call when folder encountered

    srchr.close() # done using iterator

这按预期工作正常,但 pycharm 警告我 entry.name 和 entry.is_dir() 的“未解析的属性引用”。我觉得这很奇怪,因为 Python 文档说 scandir() 返回的 DirEntry 对象存在这些属性:https://docs.python.org/3/library/os.html#os.DirEntry

看起来我的 pycharm 可能有问题,但不确定...感谢您对此事的任何帮助或详细说明,谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)