What is going on? I am using Python to fetch a directory with os but it's not working

Question:

(Sorry people who use screen readers. Image of error and code as well as directory. The image explains it all.

I am creating a decision tree and I give it a picture of either a cat or dog and it will decide whether it can detect if it is a cat or dog. I created a directory in my project called ‘Images’ and put a picture of a dog in it. Yet os cannot find the directory. I have tried many different types of ways to fetch the directory but it hasn’t worked.

Asked By: blackscratch22

||

Answers:

It looks like you’ve messed up your directory structure in the script:

  • On line 19 you append a category name to Images folder;
  • After that, you’re looking for the images in Images\Dog and Images\Cat (listdir on line 20), but Cat and Dog folders don’t exist inside Images.

Either create Cat and Dog directories inside Images and move pictures there or change your code according to the file structure.

Answered By: Max Skoryk