IDLE rapid guide

The Idle IDE provides us with two main tools:

  • The interpreter or shell that allows us to execute Python code by typing it. The result is shown immediately.

  • The editor window is the window that allows us to edit our Python code (be it a main program or one or several functions) and save it into a file. The editor also allow us to execute (or run) the code of the open file anytime.

Executing IDLE

To execute IDLE simply call the idle application from the application manager.

Alternatively you can call it from the terminal:

$ idle &

The & is an option that launches idel while keeping the terminal running in parallel.

Firstly, the Python shell is launched with the promp ‘>>>’ that allows you to type any Python code.

Editing with Idle

The editor can be launched to create a new python file or to edit an existing file (File/Open).

Once you are done, close IDLE selecting the File/Exit menu option.

The first time we work with a file we have to give a name to it.

Warning

If the Python files *.py, *.pyw) option is selected in the drop-down menu Files of type, it will not be necessary to add the extension .py at the end of the filename to indicate that it contains Python code, because IDLE will do it automatically.

Warning

A file name must only contain one dot separating the name and the extension py.

To open an existing file we have to select the menu option File/Open and a dialog will be displayed that will allow us to select the file to open or browse other directories to find it.

When we finish working with a file, it is advisable to close the window before opening another one with the File/Close menu option or directly with the 'X' button.

Program and functions execution

You can execute the code of the file by:

  • 1.- Openning it ith the editor.

  • 2.- Select the Run/Run Module menu option. The code is executed and the result is shown in the shell window.

To execute a function, we select the Run/Run Module menu option from the editor window where this function is located. If the following message appears, it means that the function has been imported and a reset of the shell has been made.

>>> ============== RESTART ==============
>>>
>>>

Once imported, we can execute the function by simply calling it with its name and the values we want to use as parameters.

If we try to run Run Module and some new code has not been saved, IDLE will ask us if we want to save it before importing it. If we answer OK, first the code will be saved and then the function imported. Conversely, if we answer Cancel, we will return to the editor window and the function will not be imported.

When we import a Python function IDLE can detect syntax errors. In this case, IDLE will indicate it with a red message within the editor window.

Warning

We have to repeat the previous steps whenever we modify the code of a function in the editor window.

Doctests execution with IDLE

See exercise temes/test/Doctest_idle/index

Other aspects

We have to define a working directory for each lab session and save in it all the related files: files with Python code, testfiles and data files.

To recover previous IDLE commands we can use the key combinations ALT-p and ALT-n.