Visual Studio Code - Opening Files with Python open()
When running Python files using Run Python File in Terminal, Visual Studio Code runs the Pythn file using an absolute path. For example:
python "/Users/natdunn/Documents/Webucator/ClassFiles/file-processing/Solutions/list_creator.py"
Follow these instructions to set up Visual Studio Code to run the file from the directory it is in.
- Select Settings from the Code > Preferences menu:
- Add the following line to your User Settings:
"python.terminal.executeInFileDir": true,
- The next time you run a Python file using Run Python File in Terminal, it will change the directory before executing the file:
Nats-MacBook-Pro:Webucator natdunn$ cd "/Users/natdunn/Documents/Webucator/ClassFiles/file-processing/Solutions" Nats-MacBook-Pro:Solutions natdunn$ python "/Users/natdunn/Documents/Webucator/ClassFiles/file-processing/Solutions/list_creator.py"
Happy Pythoning!