I'm reading a code on Neural Networks, i have this code:
test_dir = os.path.join(dataset_dir, 'test')
test=os.path.join(test_dir,'images/img')
image_filenames=next(os.walk(test))[2]
which is a simple access to a directory that contains my testing data.
The question is: what does the [2]
mean used after the next
function?
I've been searching on google, but i didn't find anything about it.
os.walk()
yields a 3-tuple, consisting of (dirpath, dirnames, filenames)
. The [2]
just grabs the 3rd element of that tuple, as tuples are 0-indexed in python. So the returned value is filenames
.