In this tutorial, we will check how to write Python scripts and run them using IDLE.
As we have seen in the previous tutorials, we can easily run Python commands on a Python interpreter, either on IDLE or on the command line. Nonetheless, if we want to write larger and more complex programs, it becomes impracticable to send the commands one by one.
Furthermore, if some command takes a while to run, it is not feasible to have someone waiting for it to finish to send the next commands.
Thus, the most practical way of running Python code is on a script, which is a sequence of instructions that will be interpreted by the Python interpreter. In this case, we don’t need to manually send the instructions one by one.
Python scripts can be written in a text file, with a .py extension, and can run from the command line. Nonetheless, in this tutorial, we will check how to do it with IDLE, a Python IDE (Integrated Development Environment).
This tutorial was tested on a Raspberry Pi 3 model B+, running version 4.9 of Raspbian, installed using NOOBS. Nonetheless, it should also work with a Python installation on a regular computer.
Since we are going to use IDLE, the first thing we need to do is opening this IDE. I’m using Python 3.x, but the procedure to run the script on Python 2.x should be similar.
So, to open IDLE, go to the main menu and select Programming. Then, on the list of tools that will be displayed, choose Python 3 (IDLE), as indicated in figure 1.
print("Hello World") for x in range(0,10): print(x)