Photo conversion gets 3/4. What is the problem?

Question:
Why 1 photo won’t convert with others?

In this image processing exercise other images convert every time, BUT 1 photo won’t (at first it was always bulbasaur, now it is suddenly pikachu).
OR all might convert if I have a mistake with the .jpeg .png endings.
Based on terminal output the loop has gone through all photos.

Repl link:
replit.com/@Monco-Carser/Image-processing-exercise#main.py

code snippet

import os
from PIL import Image

#check if /newimages exists and if not, create it
files = os.listdir()
if "newimages" not in files:
    os.mkdir("newimages")


#loop through the Pokedex, convert photos, save in new location
for filename in os.listdir("Pokedex"):
    img = Image.open(f"Pokedex/{filename}")
    clean_name = os.path.splitext(filename)[0]
    img.save(f"newimages/{clean_name}.png", "png")
    print(f"{clean_name} done")

it seems to work fine consistently for me :thinking: are you sure it isn’t an issue with your browser not loading the photos correctly?

1 Like

Works perfectly for me!

1 Like

Thanks guys for checking. :thinking: I haven’t understood why this happens as everything should be fine, as you tested.
I re-uploaded the photos (which come with the lesson I’m doing) and then only 2/4 photos saved into the file every time I run the code :rofl: :rofl:

So in the end I added try-except at the end and this does finally get all images saved for me.

3 Likes