[Tutor] Tutoring help automating with python

Fatima Mehak bossladyofthefuture at gmail.com
Wed Jul 26 16:17:54 EDT 2023


Hello,
I've been getting errors when trying to run the below text file. I have
indicated the error at the bottom for review. Can you please assist?


#!/usr/bin/env python3

from PIL import Image
import os, sys

def resize_rename_rotate(srcfile, targetdir="", size=(128,128)):
        targetfile = os.path.splitext(srcfile)[0]
        extension = os.path.splitext(srcfile)[1]

        if srcfile != tgtfile:
            try :
                 im = Image.open(srcfile)  # open file
                 im.rotate(90) # degrees counter-clockwise
                 im.resize((128, 128)) # resize the file
                 im.save(targetdir+targetfile+extension,"jpeg")
            except IOError:
                print ("cannot change image for ", srcfile)

if __name__=="__main__":
        targetdir = "../output/"
        srcdir = "../input/"

        for file in os.listdir(srcdir):
             resize_rename_rotate(file,targetdir)





#*Traceback (most recent call last):
#  File "/home/student-03-61dc276e6247/./fix_image.py", line 23, in <module>
#    for file in os.listdir(srcdir):
#FileNotFoundError: [Errno 2] No such file or directory: '../input/'


More information about the Tutor mailing list