In VS Code I have a folder defined as my workspace (e.g.: "/Users/xxxx/Documents/900. PYTHON/# VS Code/Workspace/". I had there a file with Python code (main.py) which was creating and reading the file in the same folder. Name of the file which was created is: "exercise_register.csv"
I created a sub-folder "(...)/Workspace/workouts/" where I moved both the "main.py" file with code and "exercise_register.csv" file.
Now I get and error running the code:
Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: 'exercise_register.csv'
File "/Users/xxxx/Documents/900. PYTHON/# VS Code/Workspace/workouts/main.py", line 51, in review_register
with open("exercise_register.csv", "r") as file:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When I use the below code, Python creates new file in the previous folder, not in the "(...)/workouts/" folder, in which the "main.py" file was moved to.
with open("exercise_register.csv", "w") as file:
for line in data:
file.write(line)
Any suggestions how to solve this?
I expected to have the file opened from the same folder where my "exercise.py" file is stored.
I'm adding a picture showing the folder structure to visualise my case: