我在 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()有'未解决的属性引用(unresolved attribute reference)'。我觉得这很奇怪,因为Python文档说scandir()返回的DirEntry对象具有这些属性:https://docs.python.org/3/library/os.html#os.DirEntry。
看起来可能是PyCharm出了问题,但我不确定...... 如果有任何帮助或关于此问题的详细说明,将不胜感激,谢谢!