Open a cmd.exe, command.exe or powershell, and: cd c:\my\dir\ect\ory Then run your script.
Or put an os.chdir(r'c:\my\dir\ect\ory') at the top of your script. Or use file = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') BTW, "file" means something to python other than just a variable name. You can replace it, as your code below (and my example above) does, but it obscures the thing you're replacing. That's why I like to use file_ instead of file. On Wed, Apr 14, 2021 at 10:42 AM Quentin Bock <qberz2...@gmail.com> wrote: > Okay, how exactly do I do that? > Thanks > > On Wed, 14 Apr 2021 at 13:35, Dan Stromberg <drsali...@gmail.com> wrote: > >> >> >> On Wed, Apr 14, 2021 at 9:14 AM Quentin Bock <qberz2...@gmail.com> wrote: >> >>> I receive this error when I try to open a file >>> The file (what I'm trying to open) is in the same folder as the program >>> I'm >>> trying to open it from; why is it saying no such file or directory? >>> >>> this is the only part of the code that causes the error >>> >>> file = open('Egils Saga 1-15.txt', "r") >>> >>> file.close() >>> >> >> Python will try to open the file in the directory you are currently in, >> rather than the directory your program is in. >> >> Try cd'ing to the appropriate directory first. Or specify a full to your >> file in the open. >> >> >> -- https://mail.python.org/mailman/listinfo/python-list