IDLE

IDLE is an abbreviation for the integrated development learner environment.

IDLE is a preinstalled Python IDE that is written using the Python standard library tkinter. tkinter is a Python standard library which is used for graphical user interfaces.

IDLE Shell

The IDLE Shell can be launched from the Anaconda PowerShell Prompt using the PowerShell command:

idle
img_001

The IDLE Shell looks similar to a PowerShell Prompt running Python and can be used to input Python code:

img_002

Notice that when IDLE is launched, the Anaconda PowerShell Prompt will be busy. Essentially a while loop is running in the Anaconda PowerShell Prompt to keep idle open. It will remain busy until IDLE is closed:

img_003

Code Completion and Docstrings

If p is input followed by a , a list of Python builtins identifiers displays:

img_004

And if a function is input with open parenthesis for example print( a docstring will display:

img_005

If a Python standard module is imported such as:

import builtins

And if builtins. is input followed by a , a list of Python identifiers from that module displays:

img_006

If the following object instance is instantiated:

obj1 = object()

Inputting obj1. followed by a , shows a list of Python object based data model identifiers:

img_007

If the following string instance is instantiated:

str1 = 'hello'

Inputting str1. followed by a , shows a list of Python str identifiers:

img_008

Inputting str1._ followed by a , shows a list of Python object based data model identifiers that the str class also has:

img_009

If a third-party data science library such as numpy is imported using the alias np:

import numpy as np

Inputting np. followed by a , shows a list of identifiers from the numpy library:

img_010

IDLE Doc

The IDLE Doc is essentially an equivalent to Notepad that shows code completion.

To open IDLE Doc, select File → New File in the IDLE Shell:

img_011

This will open up IDLE Doc in a seperate Window. Select File → Save As…

img_012

Then save the file as a Python Script file (.py file extension):

img_013

Code completion will now work in a similar manner to seen in the IDLE Shell:

img_014
img_015
img_016
img_017

Code completion with the IDLE Doc will only work with third-party libraries and instances of classes from third-party libraries if they are previously imported in the IDLE Shell. If a script file includes

import numpy as np

And np. is input followed by a the completions display:

img_019

If the same is done with pandas which is imported in the script file but not in the Shell, inputting pd. followed by a does not display any identifiers:

img_020

Importing pandas in the Shell:

img_021

Now allows identifiers to display in the script editor:

img_022
img_023

A simple script file:

print('Hello World!')

can be created:

img_024

It can be run by selecting, run → run module:

img_025

The print statement created in the script file will now be seen in the Shell:

img_026

A script file which uses the data science libraries can be created:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 2, 4, 6, 8])
df = pd.DataFrame({'x': x),
                   'y': y})

plt.plot(df['x'], df['y'])
plt.show()
img_027

This script file can be run:

img_028

IDLE uses the TkAgg backend for Matplotlib and the plot displays in a seperate window. The console will remain busy until the plot is closed:

img_029

When IDLE is closed, the Anaconda PowerShell Prompt will no longer be busy and a new Prompt will appear:

img_030

Return to Anaconda Tutorial