0

I've been using VSCodium lately and writing Python code with it. However, I can't seem to find a way to open an existing file when running the script with VSCodium.

This is the code I have, it's working perfectly fine when ran from a terminal, it works. But not with VSCodium.

def remove_e_words(path,path_copy):
    newfile = open(path_copy,"w")
    orig = open(path,"r")

    lines = orig.readlines()

    for line in lines:
        newfile.write(sans_e_spec(line)+"\n")

    newfile.close()
    orig.close()

Here's the error I have :

FileNotFoundError: [Errno 2] No such file or directory: 'vers-queneau.txt'

I've searched for similar issues on stackoverflow, I've tried this: Can't run python code through VS Code. Can't open file ptvsd_launcher.py [Errno 22] Invalid Argument

I have the downgraded version, it still doesn't work.

I also tried to use the file directory instead, changing a parameter in the Settings, it also didn't fix the issue.

What could I do to be able to solve this problem please?

Thanks.

VDS-Atomic
  • 115
  • 1
  • 11

1 Answers1

0

You probably don't have the current working directory set to what you expect. If you run your code with print(os.getcwd()) you will very likely find that is not the directory you expect it to be. Either adjust your relative file path to take that cwd into account or specify the path in an absolute fashion (if the file is next to the file you're running you can calculate its location based on __file__).

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40