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

2024-05-14 21:21:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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可能有问题,但不确定。。。在此问题上的任何帮助或详细说明都将不胜感激,谢谢


Tags: orpathnameforoswithplusfiles

热门问题