0

I tried making a simple game, but every time I try to run the code I get an error in the images location. Python can't find it. I tried putting the images in the desktop, or even using "import os", but neither work.

How can I make Python identify the correct filepath and run the following code:

walkRight = [pygame.image.load(os.chdir("C:\\Users\\Anas\\Desktop\\Game\\R1")),
pygame.image.load(os.chdir("C:\\Users\\Anas\\Desktop\\Game\\R2")), 
pygame.image.load(os.chdir("C:\\Users\\Anas\\Desktop\\Game\\R3")),
pygame.image.load(os.chdir("C:\\Users\\Anas\\Desktop\\Game\\R4"))]
APhillips
  • 1,175
  • 9
  • 17
  • 1
    What's with the `chdir` command? Please refer to the documentation and see what it returns -- you *cannot* `load` the result of that function. – Prune Nov 25 '19 at 19:06

1 Answers1

1

Don't use os.chdir in this case. It changes the current working directory to the given path. You can use os.path.normpath to normalize the path. You can also check for debug purposes if the file actually exists with os.path.isfile.

Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
Wouterr
  • 516
  • 7
  • 16