【问题标题】:Error: glob() got an unexpected keyword argument 'root_dir'错误:glob() 有一个意外的关键字参数 \'root_dir\'
【发布时间】:2022-10-24 17:25:46
【问题描述】:

我正在运行一个 python 脚本

if len(glob.glob(path + "/*.xlsx", root_dir=".")) > 0:
  print('Found') 
else:
  print("Enter a valid path.")

我不断收到此错误:

TypeError: glob() got an unexpected keyword argument 'root_dir'

我正在使用 Python 3.8

【问题讨论】:

    标签: python-3.x glob


    【解决方案1】:

    glob.glob 在 Python 3.10 中获得了 root_dir 和 dir_fd 参数。

    Package description

    你可以这样做:

    def search_xlsx(rootdir):
        file_list = []
        for root, directories, file in os.walk(rootdir):
            for file in file:
                if(file.endswith(".xlsx")):
                    file_list.append(file)
        return file_list
    

    【讨论】:

      猜你喜欢
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 2017-09-12
      相关资源
      最近更新 更多