Writing, Saving and Running Python Programs with IDLE

Writing, Saving and Running Python Programs with IDLE

Entering commands at the prompt is just the beginning. Let’s use IDLE to save and run files. With this skill you’ll be able to write and build complex and powerful Python programs. IDLE has two modes: interactive and script. We wrote our first program, “Hello, World!” in interactive mode. Interactive mode immediately returns the results of commands you enter into the shell. In script mode, you will write a script and then run it.

Let’s create a module. We’ll cover modules in depth later. For now, all you need to know is that a module is a file containing Python code ending in the suffix:

If it’s not already running, start IDLE. Using IDLE is very similar to using a text editor. Under File, select New Window or press Ctrl + N. That will bring up a new window titled, “Untitled”.


Enter this command in the Untitled window:

We need to save our file before we can run it. So under File, select Save. At the prompt, name it something clever like:

And save it somewhere you can find it later.

Now the fun part. Under Run, select Run Module.

Running a Python program in IDLE

Now go back to the Shell. What’s this RESTART business? The Shell is restarted every time you run a module in IDLE. That’s to clear out any old settings that might interfere with your program. Below the RESTART line you should see:

Running a Python program in IDLE

It’s not much of a joke without a punchline. Let’s modify our module. Change the following:

Let’s run that again, this time with the keyboard shortcut: F5. Try that.

In the Shell you’ll see our joke printed, but where’s the punchline? Notice that there isn’t a prompt? That’s because the Shell is waiting for your input. Press any key.

Running a Python program in IDLE

I love that joke. It’s so good and so bad. Know what I mean? Know what I mean? Nudge nudge, say no more.

Perform mathemagical feats in our next lesson on Python operators.

Writing, Saving and Running Python Programs with IDLE was posted by on . Jared likes to make things. He really wants you to watch The Hello World Program so you can learn the skills you need to build an awesome future. His contributions to the show include puppetry, 3D animation, doodling and speaking in a bad British accent. And yes, that is a fox sitting on his face.

Discuss this article in the Comments below, or and it with your friends. Learn more about Python by subscribing to The Hello World Newsletter .

Join the Discussion
  • newguy01

    invalid character in identifier with the word “what”s”. Using 3.4.1 here. Is that why?

  • Sorry about the late response. I’m sure you figured this out by now. Or moved on. At any rate, your Python version is fine. You are using double quotes for the apostrophe. Try “what’s”.

  • presley

    ahhh yeah

  • Jack Smith

    Coding!! =D

  • Your dead fucking nan!

    Hello my grandson, I’m so glad I left you gay bitch ass!

  • subcook

    okay, so I am learning all programming from scratch I just happened to land on Python (using Ubuntu 14.04 – I did install idle). I already messed up and cannot figure out how. I did everything (not that there was a lot) correctly :

    input(“What’s Brown and sounds like a bell?”)

    ….and after it asks the question I hit ENTER and rather than say Dung!, it says this

    Traceback (most recent call last):

    File “/home/pleh/pleh-Python/badjoke.py”, line 1, in

    input(“What’s Brown and sounds like a bell?”)

    File “”, line 0


    SyntaxError: unexpected EOF while parsing

    I copied everything that this tutorial said. Is it because I am using Python 2.7.6 ?

  • Yes, the tutorial is covering Python 3. For Python 2.7, you need to use the raw_input() function and you don’t need to use parentheses with the print function:

    raw_input(“What’s brown and sounds like a bell?”)
    print “Dung”

    If you’re using the stable release of 14.04, Python 3 is already installed. Enter python3 at a terminal prompt.

  • Ugochukwu Victor

    I typed in ….input(“What’s brown and sound like a bell?”)
    but Dung doesn’t appear on the restart window.
    And pls how do you go to the next line since ENTER executes

Subscribe to our Mailing List

Stay up to date on the latest videos and tutorials with our monthly newsletter

The email entered is invalid