IDEs & Debugging

Creating and running our first script

An IDE is primarily a place for writing and running code. They are designed to give you a fast loop between editing a file and checking that the code you just wrote worked and so they provide an easy way of doing this.

On the left-hand side of your screen, there is a list of options under the "Project" label. The top should read "utils" (or whatever you called your project in the previous step). Right click on "utils" and go to NewPython File. This will pop up a small box which a common interface in PyCharm. In this box type first.py and press enter.

Press "New file" under "Start" on the welcome screen or go to FileNew File. This will create a new file in your folder with a name like Untitled-1.txt. The first thing we want to do is rename it to have a .py extension so that VS Code knows that it is a Python file. Go to FileSave as... and name the file first.py.

At this point, since VS Code has recognises the .py extension it will start asking you questions about Python tools.

It may pop up a window in the bottom-right saying The 'Python' extension is recommended for this file type. In this case, press Install.

If it asks you about "Linter pylint is not installed." then select "Install". Likewise for any other Python tools it asks about.

We're going to start with a very simple file so for now, just put the following code into the file:

first.py
print("Hello")

Now that the Python file has some code in it, we are going to ask the IDE to run the script. In the past you may have run your Python code by typing python first.py in a terminal or by writing it in a cell in a Jupyter Notebook. IDEs provide a similar and simple way of running your scripts.

To run the script, press the green triangular play button () in the top-right.

This will run the script and give the output in a tab at the bottom. You should see the word Hello printed.

Exercise

Change the script to print a different string and re-run it. Make sure that you see your new string printed to the output.