Helen Frost
Helen Frost

Reputation: 3

VSC python won't open .txt files in the same directory (relative path only works for the top level of the workspace folder)

I get: FileNotFoundError: [Errno 2] No such file or directory:'movies.txt' for this line:

with open("movies.txt", "r", encoding= "utf-8") as movies:

So far (from what I've tried) I'm figuring it's a VSC workspace/file nesting depth issue...maybe some settings I don't know exist somewhere.

Is there a way to fix this? Should I stop using nested files? How many levels of nested files are okay? (I'm 3 levels down from my main workspace folder) New to coding and VSC (using desktop version) so not sure what's good practice for organising files.

Some stuff I've checked/tried:

Upvotes: 0

Views: 41

Answers (1)

Rutvi Rajesh
Rutvi Rajesh

Reputation: 74

import os
print(os.getcwd())

Check your current working directory or you can specify full path to the file like below :

with open("/full/path/to/your/movies.txt", "r", encoding="utf-8") as movies:
    # code

Upvotes: 0

Related Questions