Re: Tutoring help automating with python
Cameron Simpson <[email protected]>
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <ZMGv/[email protected]> |
On 26Jul2023 15:17, Fatima Mehak <[email protected]> wrote: >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? [...] >``` > 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/' >``` This means that there's no such directory `../input/`. Because that is a relative path, it is important that when you invoke Python that it is _running_ in the right directory for that path to work. Try putting this: import os print(os.getcwd()) before the `for...` line. That will tell you the current working directory Python is using, and hopefully that will make clear why the relative path is not working - the relative path must be valid from that directory from `os.getcwd()`. Cheers, Cameron Simpson <[email protected]> _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor