As I try to do more useful things with Python, I need a more supportive environment for writing code than the REPL. Visual Studio Code offers a lot of nice features without the slowness one expects of a powerful IDE.
This post is part of my journey to learn Python. You can find the other parts of this series here.
Download and installation
Visual Studio Code (VS Code) works on Windows, Linux and Mac. You find the installers on code.visualstudio.com:
Download the installer for your platform, run it and answer the questions in the wizard. When everything is done, VS Code starts.
Add the Python extension
Microsoft created an official Python extension for VS Code. You find a detailed guide to setup your computer and VS Code for Python here. I already had a working Python installation and could skip many steps and directly install the Python extension from the Extension Marketplace:
Write your code
You can add a new file (with the *.py extension) and VS Code will give you syntax highlighting for Python. As soon as you type, it will suggest you install the Python linter, that will help you to check your code for valid Python syntax and shows a warning if you missed something.
Run your code
You can run your code by clicking the green play icon on the top right corner:
However, I find it much simpler to hit CTRL+F5. You can see the output of your code in the terminal window at the bottom of VS Code:
Debug your code
VS Code comes with a built-in debugger. You can debug your code by hitting F5 (as you do it in Visual Studio). The debugger controls show up in the middle of the top bar of VS Code and allows you to enter methods or skip over them:
To stop the debugger at the right place you need to add a break point. You can do this by clicking on the space between the left border and the line numbers:
The debugger now runs to that break point and lets you inspect the state of your code:
More things to explore
VS Code offers not only a nice integration for Python, but many other things you often use are easy to reach. Git is integrated as a first-class citizen and you can see what files are changed and on which branch you are.
If something is too tiny or is not easy to see, you can zoom the whole VS Code up to a size which works for you. The same is true for the colours. If you like another one, you can choose from various built-in templates or add more using the extension.
Conclusion
I think VS Code has a lot of potential and offers a nice integration of all the tools you need. So far, I do not have much experience, but I like what I see and I am eager to learn more.