Python Editor: Notepad++

Intro to Notepad++

Notepad++ is a highly functional, free, open-source, editor for MS Windows that can recognize (i.e., highlight syntax for) several different programming languages from Assembly to XML, and many others inbetween, including, of course, Python.

Besides syntax highlighting, Notepad++ has some features that are particularly useful to coders. It will allow you to create shortcuts to program calls, such as a Run Python menu item that will invoke python.exe to execute your Python code without having to switch over to another window running a Python shell, such as IPython.

Another very convenient feature is that it will group sections of code and make them collapsible so that you can hide blocks of code to make the page/window more readable.

Notepad++ provides indentation guides, particularly useful for Python which relies not on braces to define functional code blocks, but rather on indentation levels.

Installing and Configuring Notepad++

You can download a copy here from the SourceForge website. It should install in the directory C:\Program Files\Notepad++. If you create a new document, it will display as Normal Text under the Language menu, so it will not highlight syntax (color-code words and symbols). Following is example Python code to generate the Logistic Map:



def printIterates(OneDMap, initialConditions, nIterates):
    x=initialConditions
    for i in range(nIterates):
        x=OneDMap(x)
        print i, x

def LogisticMap(x):
    return 4.0 * x * (1.0 - x)

printIterates(LogisticMap, 0.3, 10)

As you enter the code in the new document, it appears as simply black text:



To invoke syntax highlighting, choose Python from the Language menu or save the document with a .py extension. Here, we have saved the file as LogisticMap.py:



We can add more functionality to our editor by adding a Run menu shortcut that lets us execute Python code directly in the editor, without having to switch to another Python shell window. To add a new shortcut, go to the Run menu and select Run.... This will bring up the Run... dialog box to enter our command. In the text field provided, enter
C:\Python25\python25.exe $(FULL_CURRENT_PATH) :



This tells Notepad++ to run the Python interpreter, python25.exe, on the file we currently have selected, whose path is given by $(FULL_CURRENT_PATH) . If you have multiple files open, it will only run the current file in view.

Click on the Save... button to specify the shortcut key. This will bring up the Shortcut dialog box. Enter a descriptive name for the new shortcut, such as Run Python 2.5. Then under the pull-down menu choose an UNUSED key as the shortcut key, such as F8. You can also specify any combination of modifier keys (Alt, Shift, Ctrl) if you wish to complicate things further.



Click the OK button to accept the new shortcut. This will bring you back to the Run... dialog box. Click Cancel to escape the dialog. You can now find the newly created shortcut under the Run menu:



To execute our program, you can choose the Run Python 2.5 menu item, or simply press F8. Your output should appear in a console window showing the first ten iterations of the Logistic Map. When you press Enter, the program will end and the console window will close:




Table of Contents