Concepts / Choosing and Setting Up a Python Editor

Choosing and Setting Up a Python Editor

A Python source file is a permanent record of a program. The editor displays and lets you change the code, while the saved file stores that code on your computer.

  • Programming

From Editor to Saved Program

Writing code in an editor is only the beginning. If you want to keep the program, reopen it, edit it, run it later, or share it with someone else, you must save it as a file on your computer. The essential choices are the editor, the filename, and the folder where the file will live.

Key point

A Python source file is a permanent record of a program. The editor displays and lets you change the code, while the saved file stores that code on your computer.

The .py Filename Extension

A Python source filename has two essential parts: a name you choose and the .py extension that you must include. In hello.py, hello is the chosen name and .py is the required extension. The extension tells the operating system and text editors that the file contains Python code, and it allows the Python interpreter to recognize the file as a Python program.

hellochosen name.separatorpyPython extensionfollowed byfollowed by
What changes when a filename ends in .py instead of another extension?
Filename partPurpose
helloA name chosen by the programmer
.Separates the name from the extension
pyIdentifies the file as Python source code

The three visible parts of the filename hello.py

Saving Code into a File

Plain-text editorcode is writtenSavechoose name and folderPython source filename.pyWrong filename formatnot recognized as intendedwrite codeuse .pyomit or change extension
How does code move from the editor into a saved .py file?

The saving workflow is straightforward. Open a plain-text editor, write your Python code, choose a meaningful filename, select a location, and save the file with the .py extension. When you click Save, the code in the editor is written to computer storage as the file you specified.

Worked example

Saving a Greeting Program

You have written a small greeting program in a plain-text editor and want to keep it for later use.

  1. 1
    Choose a name

    Select a meaningful name such as greet_user.py. The name describes the program, and the .py extension identifies it as Python source code.

  2. 2
    Choose a folder

    Select the dedicated folder where you keep your Python programs.

  3. 3
    Save the file

    Use the editor's Save action. The code displayed in the editor is written to storage as the file named greet_user.py.

  4. 4
    Verify the result

    Check that the file exists in the intended folder and that its filename ends in .py.

Result

The program is now stored as a Python source file that can be opened, edited, and run later.

File Contents and Editor Display

Text editordisplays codegreet_user.pystores codePython codetext written by learnerComputer storagechosen foldershowssaved aslocated in
What does a .py file contain, and how is the code shown in the editor related to the stored file?

Before saving, the code exists in the editor while you are working on it. Saving writes that code to computer storage as a file. The file is independent of the editor: after saving, you can close the editor or turn off the computer, and the file remains in the selected folder exactly as it was saved.

Key point

The editor is a tool for writing and viewing code. The .py file is the stored program. Saving creates the lasting connection between the code you wrote and the file you can reopen later.

Organizing Python Programs

A Python file can be saved in any folder as long as you know where that folder is. However, a dedicated folder makes your work easier to organize as you create more programs. Create one folder specifically for Python programs, such as Python_Programs or My_Python_Code, on your Desktop or in your Documents folder. Save your Python files there so they remain together and are easier to find and run later.

  • Create one folder dedicated to your Python programs.
  • Choose a location you can find again, such as the Desktop or Documents folder.
  • Use meaningful filenames for individual programs.
  • Use underscores instead of spaces in filenames.
  • Avoid special characters in filenames.
  • After saving, verify that the file is in the intended folder and that the name ends in .py.

Filename and Saving Mistakes

  • Common mistake

    Leaving out the .py extension

    What it looks like

    Saving a program with a name that does not end in .py

    Why it fails

    The operating system and Python interpreter rely on the extension to recognize the file as a Python source file.

    Do this instead

    Include .py at the end of the filename.

  • Common mistake

    Using a word processor instead of a plain-text editor

    What it looks like

    Writing Python code in an application that adds document formatting

    Why it fails

    The added formatting cannot be interpreted as Python code.

    Do this instead

    Use a plain-text editor for writing and saving Python programs.

  • Common mistake

    Using spaces or special characters in the filename

    What it looks like

    Choosing a filename with spaces or special characters

    Why it fails

    The recommended filename format uses underscores instead of spaces and avoids special characters.

    Do this instead

    Choose a meaningful name that uses underscores where needed and ends in .py.

  • Common mistake

    Saving programs in unrelated locations

    What it looks like

    Placing each Python file in a different folder without a consistent plan

    Why it fails

    The files become harder to find and manage as the number of programs grows.

    Do this instead

    Create one dedicated folder and save your Python programs there.

  • Common mistake

    Assuming code remains after closing an interactive shell or notebook

    What it looks like

    Closing the program without saving the code as a file

    Why it fails

    Code entered interactively runs immediately but disappears when the program is closed.

    Do this instead

    Save code as a .py file when you need to keep, reuse, or share it.

File Setup Practice

EASY

Plan how you would save a Python program that calculates a total. State the folder you would create or use, choose a meaningful filename, and explain why the filename must end in .py.

Hints
  • Use a dedicated folder for Python programs.
  • Use underscores instead of spaces in the filename.
  • The extension is .py because it identifies the file as Python source code.

What do you think happens?

You write code in an interactive shell and close the program without saving it. What happens to that code?

  • It remains automatically as a Python source file

  • It disappears when the program closes

  • It is placed automatically in a dedicated folder

Reveal answer
Answer:

It disappears when the program closes.

Code entered in an interactive shell or notebook runs immediately, but saving it as a .py file is necessary when you want to keep, reuse, or share it.

Essential Saving Rules

  1. 1
    Use a plain-text editor rather than a word processor.
  2. 2
    Save every Python program with the .py extension.
  3. 3
    Choose a meaningful filename, use underscores instead of spaces, and avoid special characters.
  4. 4
    Keep your programs in one dedicated folder so they are easy to find.
  5. 5
    Remember that saving writes the code from the editor to a lasting file on computer storage.
  6. 6
    Verify both the filename and the folder after saving.

Key Takeaways

  • A Python source file needs a name and the .py extension.
  • The .py extension helps the operating system and Python interpreter recognize the file as Python code.
  • A plain-text editor is appropriate for Python; word processors add formatting that Python cannot interpret.
  • A dedicated folder keeps Python programs organized and easy to find.
  • Saving writes the code displayed in the editor to a persistent file that can be reopened, edited, and run later.

Related concepts

More concepts starting with C