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:
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:
- 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"
Author: Nat Dunn
Nat Dunn is the founder of Webucator (www.webucator.com), a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.
Follow Nat on Twitter at @natdunn and Webucator at @webucator.