【问题标题】:path.join doesn't run with listpath.join 不与列表一起运行
【发布时间】:2019-02-09 05:31:47
【问题描述】:

当我想在我的文件夹中获取图像路径时出现错误..

路径 = os.fspath(路径)

TypeError: 预期的 str、bytes 或 os.PathLike 对象,而不是列表

这是我的代码:

root_dir = './test/' 
#######################Enumerate classes###################################
class_folders_train = glob.glob(os.path.join(root_dir, '*'))
print("class_folders_train :",class_folders_train)

train_paths = []
    for idx, class_folder in enumerate(class_folders_train):
        print("ok")
        image_paths = glob.glob(os.path.join(class_folders_train, '*.tif'))
        print("image_paths :",image_paths)
        train_paths.extend([(im_path, idx) for im_path in image_paths])
    print("train_paths :",train_paths)

所以我的代码在 print("ok") 之后就死掉了...

【问题讨论】:

    标签: python image list path


    【解决方案1】:
    image_paths = glob.glob(os.path.join(class_folders_train, '*.tif'))
    

    您在这里可能指的是class_folder,而不是class_folders_train

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多