user288609 user288609 - 2 months ago 8
Python Question

regarding the parameters in os.path.join

I am trying to reproduce a python program, which includes the following line of code

data = glob(os.path.join("./data", config.dataset, "*.jpg"))

My guess is that it will capture all
files stored in
folder. But I am not sure the usage of
here? Should the folder structure look like
The reason I need to understand this is because I need to create a data input folder to run the program. The original program does not share the detail on the data organization.


config.dataset in your code fragment is a variable. It's either a dataset attribute of some config object, or the dataset global variable in an imported config module (from this code's perspective they work the same).

As a few people have commented, for that code to work, config.dataset must evaluate to a string, probably a single directory name. So the result of the join call will be something like "./data/images/*.jpg" (if config.dataset is "images"). The variable could also have a (pre-joined) path section including one or more slashes. For instance, if config.dataset was "path/to/the/images", you'd end up with "./data/path/to/the/images/*.jpg".