[Tutor] Tutoring help automating with python

ThreeBlindQuarks threesomequarks at proton.me
Wed Jul 26 19:52:30 EDT 2023


Fatima,

Check what folder the program thinks it is in.

Then check if the parent directory has a subdirectory with the name needed and contents.

My guess is the current directory has not been set to where you want it to be or that one level up has not been initialized as anticipated.

Q


Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, July 26th, 2023 at 4:17 PM, Fatima Mehak <bossladyofthefuture at gmail.com> wrote:


> 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/'
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list