2

So I have an assignment for college in python and for a part of it, I need to open the file "voting.txt". I coded up the assignment in Pycharm, as that's the IDE we use in college, but my preferred IDE is VSCode. In Pycharm the code works fine. I run the code and I get the results I want. However, when I try to run the code in VSCode, I get a FileNotFoundError. The file I want to open is in the same directory as the code that opens it. I don't know whether there's a setting that tells VSCode to look for the file in a specific directory, or what, but I'm hoping someone will have a solution. Below is the python code to open the file, so as you can see, the syntax is correct, and as i said, the text file and the python file containing the code that opens it is in the same directory:

fileOut = open("voting.txt", "r")
ConorH99
  • 25
  • 6
  • 2
    Possible duplicate: https://stackoverflow.com/questions/49143852/trouble-opening-files-in-python-with-vs-code – Taher A. Ghaleb Nov 18 '18 at 01:59
  • Try using absolute path instead. The working directory (`os.getcwd()`) is probably different between your VSCode and PyCharm. – r.ook Nov 18 '18 at 03:36
  • 1
    Possible duplicate of [Trouble opening files in python with VS Code](https://stackoverflow.com/questions/49143852/trouble-opening-files-in-python-with-vs-code) – quant Nov 18 '18 at 07:25
  • Is it possible to open a file in the VSEditor from a python script. Such as `code 'file.py'` – Timo Dec 29 '20 at 18:23

0 Answers0