Skip to main content
Engineering LibreTexts

5.3: Procedure – Editor Window

  • Page ID
    26444
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    As useful as the output shell window is, you will not be able to easily edit and save programs from it. For this, you’ll need an editor window. From the File menu of the output window select New File. A second window will pop open. It will not contain a cursor. This is a simple text editor. It will not interpret lines as you type them. The edit window is where you will normally write your programs (occasionally going back to the output to see results or to use its “scratch pad” feature).

    One of the most useful operators in Python is #, which is used for comments. That is, Python will ignore anything on a line that follows this symbol; it’s for human consumption only. This is how you can place documentation inside a program. By doing so, the code and documentation can never get separated. Type in the following two line program:

    # This is my first Python program
    print( “Hello World!” )
    

    The editor works like any other text editor that you might have used. That is, you can insert, delete, cut, copy, paste, etc. Unlike a word processor, there is no selection for font, margins, and the like. After all, the point is to write down commands. Python and the computer don’t care how pretty those lines appear.

    To run the program, go to the Run menu and select Run Module. You will be prompted to save the program. NEVER save your code to the hard drive on a lab computer. ONLY save to either your student account space or to an external USB drive. It is suggested that you create a folder on your student account for Python programs and store everything there, using a USB drive as a backup.

    When naming a Python program, a .py extension must be used. Failing to do so will result in code that will not be recognized by the system as a Python program. For this exercise, it is suggested that the program be saved as hello.py

    After the filename is entered, select Save. Python will now load your code and start executing it (i.e., performing the commands you entered). Move back to the output window. You should see the following at the bottom:

    Hello World!
    

    Note that Python will not perform any spell or grammar checking for you. So if you spelled World as Whirled, that’s what it will print out.

    Go back to the edit window. You will note that your code is now color coded. It will not do this until the program is saved as a .py file. Consequently, it is suggested that after typing in the initial comment header (name, date, program title and description), the program should be saved in order to engage the color coding. This can be very useful for spotting typos and syntax errors once you get used to the color scheme.

    In general, the process of developing a program will involve entering and editing code and then saving and running it. The output is then examined to see if it is proper. If not, the code is edited or added to, resaved, and rerun until the output is correct. This process may be repeated many, many times. In larger programs, the task is usually broken into smaller and more manageable chunks, each tested successfully before continuing to the next portion.

    Let’s edit this program. Sometimes it is useful to print out an entire block of text formatted a certain way (program directions for the user, for example). This can be accommodated through a triple quoted string. Go to the editor window, alter the existing lines and add the new lines so that your program looks like this (include extra spaces as shown in the second print statement:

    # This is my second Python program
    print( “Hello World!” )
    print( ” ” ”
    Look at the odd formatting of   these    lines.
         They will show up as defined!
    ” ” ” )
    

    Save and run the program. Do you get the results you expected?

    It is a good idea to periodically re-save your code if you have made several modifications since the last execution. Few things are more frustrating than losing code because a computer locked up.

    At this point, try experimenting with different assignment and print statements. This is a good habit to get into. You can’t “break” the computer by typing in improper code. Usually the worst that will happen is that you’ll get a syntax error. Consequently, one of the best ways to remember program statements and syntax is to try little snippets of code and see if they do what you expect. The simple act of typing in code will help you remember the details. For this reason, do not make use of cut and paste, at least not until you have mastered the syntax of the language.

    Once your coding is done for the time being, save your code, make sure that you close any Python windows and then proceed to shut down the computer.


    This page titled 5.3: Procedure – Editor Window is shared under a not declared license and was authored, remixed, and/or curated by James M. Fiore.

    • Was this article helpful?