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 可能有问题,但不确定...对此事的任何帮助或详细说明表示赞赏,谢谢!
| 归档时间: |
|
| 查看次数: |
799 次 |
| 最近记录: |