[英]why is glob.glob returning an empty list?
Please i need help.请我需要帮助。 I am using windows.
我正在使用窗户。 I am getting an empty list when I run this glob code.
当我运行这个 glob 代码时,我得到一个空列表。 my ipynb file is inside the code folder, and I have 4 different folders inside the train and test folders that serve as labels for my image task.
我的 ipynb 文件位于代码文件夹中,并且我在 train 和 test 文件夹中有 4 个不同的文件夹,它们用作我的图像任务的标签。
# Setup train and testing paths
train_dir = "code/Datasets/train/**/*.jpg"
test_dir = "code/Datasets/test/**/*.jpg"
train_dir, test_dir
check = glob.glob(train_dir)
print(check)
I also tried pasting some images to enable me try this and it did not work我还尝试粘贴一些图像以使我尝试此操作,但没有成功
train_dir = "code/Datasets/train/*.jpg"
Two possible issues:两个可能的问题:
**
in your glob
path, you fail to pass recursive=True
, so it won't actually treat **
as specialglob
路径中使用**
时,您无法通过recursive=True
,因此它实际上不会将**
视为特殊import os
, print(os.getcwd())
.import os
, print(os.getcwd())
。 Is your working directory the one that contains code/Datasets/...
?code/Datasets/...
? Relative paths like this require a specific working directory (separate from the script directory).__file__
, eg train_dir = os.path.join(__file__, "code/Datasets/train/**/*.jpg")
__file__
的路径,例如train_dir = os.path.join(__file__, "code/Datasets/train/**/*.jpg")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.