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

use*_*967 5 python 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
Run Code Online (Sandbox Code Playgroud)

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

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

use*_*967 2

看起来这是 pycharm 的一个错误。那么就暂时忽略吧。谢谢史蒂夫!