python - path.join 不与列表一起运行
问题描述
当我想在我的文件夹中获取图像路径时出现错误..
路径 = os.fspath(路径)
TypeError:预期的 str、字节或 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") 之后就死了......
解决方案
image_paths = glob.glob(os.path.join(class_folders_train, '*.tif'))
你可能是说class_folder
这里,不是class_folders_train
。